我尝试在这个答案之后验证 generic.GenericTabularInline:
我哪里错了?
class DesignedPhotoInlineForm(forms.models.ModelForm):
class Meta:
model = DesignedPhoto
fields = ( 'imagefile', )
widgets = { 'imagefile': DesignedPhotoImageFieldWidget
}
class ArtistAdminDesignedPhotoInlineFormSet(generic.BaseGenericInlineFormSet):
def clean(self):
print "heh!" #should print into devserver but does not!
pass
class DesignedPhotoInline(generic.GenericTabularInline):
model = DesignedPhoto
ct_field = 'illustrated_content_type'
ct_fk_field = 'illustrated_object_id'
form = DesignedPhotoInlineForm
formset = ArtistAdminDesignedPhotoInlineFormSet
class ArtistAdmin(admin.ModelAdmin):
fieldsets = (
(
_('Main info'), {
'fields': ( ('name', 'full_name', ), ('on_top', 'show_in_menu', ), 'music_style_text', )
},
),
(
_('Profile and history texts'), {
'fields': ( 'profile_text', 'history_text',),
},
)
)
formfield_overrides = {
TextField: { 'widget': tinymce_widgets.AdminTinyMCE(attrs={'cols': 120, 'rows': 25}) },
}
inlines = [ DesignedPhotoInline, ArtistPublicationsInline, ArtistAudioInline, ArtistVideosInline ]
actions = ['create_cms_page']
def create_cms_page(self, request, queryset):
#omitted
pass
create_cms_page.short_description = _("Create pages for the selected artists")
我已经以与验证内联的第一个答案相同的方式使用它们。我只是将formset的基类更改为generic.BaseGenericInlineFormSet。