【发布时间】:2015-08-27 02:23:19
【问题描述】:
我有一个继承自 ModelAdmin 的管理类:
class TemplateAdmin (admin.ModelAdmin):
inlines = (TemplateAttributeInline, CompanyAttributeInline)
list_display = ("name", "created", "updated","departments")
list_filter = ['companies__company']
list_editable = ("departments",)
search_fields = ("name", "companies__company",)
exclude = ("companies",)
save_as = True
我想将参数传递给TemplateAttributeInline,然后它会将参数传递给TemplateAttributeForm。最好的方法是什么?
模板属性内联:
class TemplateAttributeInline (admin.TabularInline):
model = TemplateAttribute
extra = 0
sortable_field_name = "display"
form = TemplateAttributeForm
模板属性表单
class TemplateAttributeForm(forms.ModelForm):
class Meta:
model = Template
def __init__(self,*args, **kwargs):
super(TemplateAttributeForm, self).__init__(*args, **kwargs)
self.fields['attribute'].queryset = Attribute.objects.filter(#WANT TO FILTER BY THE ID OF THE COMPANY THAT OWNS THE TEMPLATE WE ARE EDITING ON THE ADMIN PAGE)
【问题讨论】:
标签: django django-forms django-admin