Re: Inserting Into Cleaned_Data Inside a ModelForm
> Now, I cant remember but I believe that if you add missing key data in > cleaned method, giving the name django would expect, you would be able > to just save the form. You could also just manually access the key > field from the cleaned_data and apply it on the model. Unfortunately, this isn't the case. This was the first thing I tried, but I found code in Django's forms/models.py that strips out cleaned data that doesn't explicitly appear in either the fields or exclude list. It's quite a frustrating and arbitrary limitation, and took me several hours to work around. Chris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---
Re: Inserting Into Cleaned_Data Inside a ModelForm
When using a modelform there are some ways to get you where you want. You can get your form using request.POST. If it validates you can save it like this creating a model. record = form.save(commit=false) record.key = 123 record.save() Now, I cant remember but I believe that if you add missing key data in cleaned method, giving the name django would expect, you would be able to just save the form. You could also just manually access the key field from the cleaned_data and apply it on the model. On 7 Mar., 18:13, Chris Spencerwrote: > On Fri, Mar 6, 2009 at 12:57 PM, rajeesh wrote: > > > You may change the save_model() method of corresponding AdminClass for > > that: > > e.g, to set the attribute 'a' of model 'Book' , write inside > > BookAdmin.save_model() something like this: > > > obj.a = form.cleaned_data['another_key'] * 2 > > obj.save() > > Won't this only effect admin? I'm looking for a general solution that > I can work into any form. > > Chris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---
Re: Inserting Into Cleaned_Data Inside a ModelForm
On Fri, Mar 6, 2009 at 12:57 PM, rajeeshwrote: > > You may change the save_model() method of corresponding AdminClass for > that: > e.g, to set the attribute 'a' of model 'Book' , write inside > BookAdmin.save_model() something like this: > > obj.a = form.cleaned_data['another_key'] * 2 > obj.save() Won't this only effect admin? I'm looking for a general solution that I can work into any form. Chris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---
Re: Inserting Into Cleaned_Data Inside a ModelForm
You may change the save_model() method of corresponding AdminClass for that: e.g, to set the attribute 'a' of model 'Book' , write inside BookAdmin.save_model() something like this: obj.a = form.cleaned_data['another_key'] * 2 obj.save() On Mar 6, 8:43 pm, Waldemar Kornewaldwrote: > On 6 Mrz., 14:13, Chris wrote: > > > I have a model that has a required attribute, but I want this > > attribute set to a calculated value based on the input from a form. So > > inside the save() method of my ModelForm class, I'm doing: > > > self.cleaned_data['requiredKey'] = 123 > > record = forms.ModelForm.save(self) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---
Re: Inserting Into Cleaned_Data Inside a ModelForm
On 6 Mrz., 14:13, Chriswrote: > I have a model that has a required attribute, but I want this > attribute set to a calculated value based on the input from a form. So > inside the save() method of my ModelForm class, I'm doing: > > self.cleaned_data['requiredKey'] = 123 > record = forms.ModelForm.save(self) Just for reference: http://groups.google.com/group/app-engine-patch/msg/a9ed56aaf326b17e Bye, Waldemar Kornewald --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---
Inserting Into Cleaned_Data Inside a ModelForm
I have a model that has a required attribute, but I want this attribute set to a calculated value based on the input from a form. So inside the save() method of my ModelForm class, I'm doing: self.cleaned_data['requiredKey'] = 123 record = forms.ModelForm.save(self) However, this raises the error "ValueError: The Record could not be created (Property requiredKey is required)". Is cleaned_data read-only? How would I modify the data used when creating the model? I realize I could probably set requiredKey as a form field, and then set it in clean_requiredKey(), but I don't want the field included in the actual form (not even as a hidden field). Any help is appreciated. Chris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---