I want to set the BooleanField inuse
to True when I save the ModelForm (I'm using a form outside of the admin area) and I'm unsure how to do it.
Models:
class Location(models.Model):
place = models.CharField(max_length=100)
inuse = models.BooleanField()
class Booking(models.Model):
name = models.CharField(max_length=100, verbose_name="Your name*:")
place = models.ManyToManyField(Location, blank=True, null=True)
Forms:
class BookingForm(ModelForm):
class Meta:
model = Booking
def save(self, commit=True):
booking = super(BookingForm, self).save(commit=False)
if commit:
booking.save()
self.save_m2m()
for location in booking.place.all():
location.inuse = True
print location #nothing prints
location.save()
View:
def booking(request):
form = BookingForm()
if request.method == 'POST':
form = BookingForm(request.POST)
if form.is_valid():
form.save()
else:
form = form
return render_to_response('bookingform.html', {
'form': form,
})
Updated to latest (see Manoj Govindan's answer). It is still not updating inuse
to True on submit / save.