获取formfield_for_dbfield中的主键

时间:2013-02-01 13:37:12

标签: python django django-admin

在formfield_for_dbfield中获取主键?

我需要在模板“add”(admin)中获取主键。

class ArticleAdmin(admin.ModelAdmin):
    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name == 'text':
            kwargs['widget'] = UploadWidget(attrs={'pk': ???? Article.PK ????})
        return super(ArticleAdmin, self).formfield_for_dbfield(db_field, **kwargs)

0 个答案:

没有答案