I wanted to have a form which displays all Records of a model(Event) in a drop down list format. This is what I did.
models.py
class Event(models.Model):
# All Fields
class AllEvents(models.Model):
event = models.ForeignKey(Event,blank=False)
forms.py
class SelectEventForm(ModelForm):
class Meta:
model = AllEvents
views.py
def testView(request):
if request.method == 'POST':
selectEventForm = SelectEventForm(request.POST)
if selectEventForm.is_valid():
# do some logic
else:
# some problem in form
This is serving my purpose. But This is allowing null values to be passed on to views. As in, If I don't select anything from drop down, no form error is raised else
condition is triggered in my views.py.
Any help ?