class ProductAdmin(admin.ModelAdmin):
form = ProductAdminForm()
class ProductAdminForm(forms.ModelForm):
def __init__(self, request, *args, **kwargs):
super(ProductAdminForm, self).__init__(*args, **kwargs)
self.fields['field1'] = forms.CharField(required=False)
self.fields['field2'] = forms.IntegerField()
如何將產品實例從ProductAdmin傳遞到ProductAdminForm?我想根據產品實例提供不同的字段。以表格形式訪問管理模型實例
看到我重新編輯答案 –