1

将 django-cms 与 django-hvad 一起使用时遇到了一些麻烦。

我定义了 2 个 TranslatableModel:

class NewsEntry(TranslatableModel):
translations = TranslatedFields(
    title=models.CharField(verbose_name='Titel', max_length=255),
    slug=models.SlugField(verbose_name='Slug', help_text='Dient zur Bildung der URL', unique=True),
    lead=models.TextField(verbose_name='Lead'),
    content=HTMLField(verbose_name='Inhalt'),
    image=FilerImageField(verbose_name='Bild', blank=True, null=True),
    yt_video=models.CharField(verbose_name='Youtube-Video-ID', max_length=50, blank=True),
    yt_thumbnail=FilerImageField(verbose_name='Youtube-Thumbnail', blank=True, null=True, related_name='news_yt_thumbnail')
)

target_group = models.ForeignKey(TargetGroup, verbose_name='Zielgruppe', related_name='news_entries', blank=True, null=True)
date = models.DateField(verbose_name='Datum')
published = models.BooleanField(verbose_name=u'Veröffentlicht', default=True)
image_gallery = FilerFolderField(verbose_name='Bildergalerie', null=True, blank=True)
image_gallery_thumbnail = FilerImageField(verbose_name='Galerie-Vorschaubild', null=True, blank=True, related_name='news_gallery_thumbnail')

class Meta:
    ordering = ['date']
    verbose_name = 'News-Eintrag'
    verbose_name_plural = u'News-Einträge'

def __unicode__(self):
    return self.lazy_translation_getter('title')




class NewsEntryLink(TranslatableModel):
translations = TranslatedFields(
    title=models.CharField(max_length=255, verbose_name='Titel')
)
entry = models.ForeignKey(NewsEntry, verbose_name='News-Eintrag', related_name='links')
page_link = PageField(verbose_name='Seite', blank=True, null=True)
external_link = models.URLField(verbose_name='Externer Link', blank=True, null=True)

class Meta:
    verbose_name = 'News-Link'
    verbose_name_plural = 'News-Links'

def __unicode__(self):
    return self.lazy_translation_getter('title')    

NewsEntryLink有一个外键到NewsEntry. 在这些模型的管理员中,我添加了以下类(带有内联):

class NewsEntryLinkAdmin(TranslatableTabularInline):
model = NewsEntryLink
extra = 1
fields = ('title', 'page_link', 'external_link')

class NewsEntryAdmin(TranslatableAdmin):
inlines = [NewsEntryLinkAdmin, ]

fieldsets = (
    (None, {
        'fields': (('title', 'slug'), 'lead', 'image', 'content', 'target_group', 'date', 'published')
    }),
    (u'Zusätzliche Inhalte', {
        'fields': (('yt_video', 'yt_thumbnail'), ('image_gallery', 'image_gallery_thumbnail'))
    }),
)

def __init__(self, *args, **kwargs):
    super(NewsEntryAdmin, self).__init__(*args, **kwargs)
    self.prepopulated_fields = {'slug': ('title',)}

admin.site.register(NewsEntry, NewsEntryAdmin)

当我现在访问该管理页面时,我收到以下 JS 错误:Uncaught TypeError: undefined is not a function (index):743

并且无法添加新的内联模型(链接不存在)并且选项(页面)不可用。

你们有什么想法吗?

4

0 回答 0