如何在admin中验证通用内联

时间:2012-10-03 05:01:31

标签: django django-admin

我尝试在这个答案之后验证generic.GenericTabularInline:

Validate inlines before saving model

我错在哪里?

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。

0 个答案:

没有答案