在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)