Issue
I am trying to add dynamic choice field to adimin form, but I get an error:
The value of 'form' must inherit from 'BaseModelForm'.
What am I doing wrong?
(part of 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
Solution
Your ReservationForm
does not extend BaseModelForm
or any of its subclasses. Change it to:
class ReservationForm(forms.ModelForm):
Answered By - Selcuk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.