Been struggling over at 
http://stackoverflow.com/questions/3652585/simple-django-form-model-save-question
to get a solution.

I want the inuse field to update to to True when LocationForm is
saved.  For example there would be a list of locations added by the
admin (London, New York and Paris) all with inuse of False.  The user
would select London and submit the form and the inuse field for London
would become True.

Models and forms:

class Location(models.Model):
    place = models.CharField(max_length=100)
    inuse = models.BooleanField()
    class Meta:
        ordering = ('place', 'id')

    def __unicode__(self):
        return self.place

class LocationForm(ModelForm):
    class Meta:
        model = Location

class Booking(models.Model):
    name = models.CharField(max_length=100, verbose_name="Your
name*:")
    place = models.ManyToManyField(Location, blank=True, null=True)

    def __unicode__(self):
        return self.name

class BookingForm(ModelForm):

    class Meta:
        model = Booking

        def save(self, commit=True):
                booking = super(BookingForm, self).save(commit=False)
                if commit:
                        booking.save()
                        for location in booking.place.all():
                                location.inuse = True
                                location.save()


Code saves fine but the location.inuse field is not saved to True.
Any ideas where I'm going wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to