Re: Issue when saving a model form

2009-11-27 Thread jul
thank you. Excluding city from the ModelForm seems to work as well... class AddRestaurantForm(ModelForm): rating = forms.IntegerField(widget=forms.Select(choices = RATING_CHOICE), required=False) city = forms.CharField(max_length=100) class Meta: model = Restaurant ex

Re: Issue when saving a model form

2009-11-27 Thread Steve Howell
I am not fully tracking to the problem here, but when it comes to overriding save() behavior on forms, I find the following helper to be handy: def build_instance_from_form(model_form): instance = model_form.save(commit=False) return instance Then in your view code do something like this:

Re: Issue when saving a model form

2009-11-27 Thread jul
The problem is that city name is not unique. Can I pass the city instance in the overrided AddRestaurantForm's save method? thank you On Nov 27, 5:12 pm, Tim Valenta wrote: > Try overriding your AddRestaurantForm's "save" method: > >     def save(self, commit=True): >         self.instance.city =

Re: Issue when saving a model form

2009-11-27 Thread Tim Valenta
Try overriding your AddRestaurantForm's "save" method: def save(self, commit=True): self.instance.city = get_object_or_404(City, name=self.instance.city) # Finish by passing control back to the normal Django flow: super(AddRestaurantForm, self).save(commit) I think th