Simple formulario Django / modelo guardar pregunta

Quiero configurar el valor de inuse en True cuando guardo el ModelForm (estoy usando un formulario fuera del área de administración) y no estoy seguro de cómo hacerlo.

Modelos:

 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) 

Formas:

 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() 

Ver:

 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, }) 

Actualizado a más reciente (ver la respuesta de Manoj Govindan ). Todavía no está actualizando su inuse en Verdadero al enviar / guardar.

 class BookingForm(ModelForm): class Meta: model = Booking def save(self, commit=True): booking = super(BookingForm, self).save(commit=False) booking.inuse = True if commit: booking.save() 

Aquí está mi puñalada:

 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 location.save() 

Actualizar

Código completo que he usado:

 # models.py 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.py 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 location.save() In [1]: from test_app.forms import BookingForm In [2]: from test_app.models import Location # I had already saved some `Location` instances. In [3]: data = dict(name = 'MyCity', place = [p.id for p in Location.objects.all()]) In [4]: f = BookingForm(data) In [5]: f.save() In [6]: for each in Location.objects.all(): ...: print each.place, each.inuse ...: PlaceA True PlaceB True PlaceC True