我正在尝试将动态选择字段添加到管理表单,但出现错误:
The value of 'form' must inherit from 'BaseModelForm'.
我究竟做错了什么?
(属于admin.py)
class ReservationForm(forms.Form):
class Meta:
model = Reservation
def __init__(self,*args, **kwargs):
super(ReservationForm, self).__init__(*args, **kwargs)
if not self.request.user.is_superuser:
self.fields['status'] = forms.ChoiceField(STATUS_CHOICES = ( (PENDING,'Pending'),(APPROVED, 'Approved'), (CANCELED, 'Canceled') ))
# Reservation
class ReservationAdmin(admin.ModelAdmin):
form = ReservationForm
最佳答案
您的ReservationForm
不会扩展BaseModelForm
或其任何子类。更改为:
class ReservationForm(forms.ModelForm):
关于python - “form”的值必须继承自“BaseModelForm”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29112847/