我在管理站點中的ModelAdmin對象的TabularInline內聯中重寫Formset時遇到問題。我知道你應該有一個與TabularInline對象關聯的模型,但我不確定如何在用於生成formset的表單對象上指定此模型。用下面的代碼,我得到「'AppAssetInline.formset'不從BaseModelFormSet繼承。」在TabularInline Django管理員表單中重寫formset
class AppAssetForm(forms.ModelForm):
model = App.assets.through
primary = forms.BooleanField()
uuid = forms.CharField()
class AppAssetInline(admin.TabularInline):
model = App.assets.through
AssetFormset = formset_factory(AppAssetForm)
formset = AssetFormset
class AppAdmin(admin.ModelAdmin):
inlines = [AppAssetInline,]