我有一个模型,它具有作为属性的另一个模型的外键。我想在与其他属性相同的管理页面上编辑forienkey&#d; d模型的属性。我在语法上苦苦挣扎 - 它根本就没有被改变。目前我的模型看起来像
class MyModel(models.model):
fk = models.Foreignkey(OtherModel)
other_attribute = CharField(...)
class OtherModel(models.model):
field_i_want_to_edit = BooleanField(default=False)
,表格是:
class MyModelAdminForm(ModelForm):
class Meta:
model = models.MyModel
fields = '__all__'
def __init__(self, *args, **kwargs):
super(MyModelAdminForm, self).__init__(*args, **kwargs)
self.fields['other_attribute'].label = "Edit this one"
REC_CHOICES = [
('Choice1', 'Remove All things'),
('Choice2', 'Add some things'),
]
FLAGGED_CHOICES = [
(True, 'Flag This One'),
(False, 'Remove Flag'),
]
edited_recommendation = ChoiceField(choices=REC_CHOICES)
fk__field__i_want_to_edit = ChoiceField(choices=FLAGGED_CHOICES)
但是当我在field_i_want_to_edit
的管理页面上选择我想要的条目时,它并没有改变。有什么想法吗?