On Sun, Aug 24, 2008 at 4:56 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]>wrote:
> > Hello, > > I have a form that I have created and it works fine. I am now trying > to save this form. The data returned from the form spans a > relationship and should update 2 tables associated by a foreign key. > > From what I have read on the docs, because it is an unbound form I > need to write my own save method. This is what I have been trying: > > from django import forms > from project.pastebin.models import loggenerator > from project.pastebin.models import entry > from project.pastebin.models import submittedlog > > > class pasteForm(forms.Form): > loggenerator = forms.ModelChoiceField(loggenerator.objects.all()) > log = forms.CharField(widget=forms.Textarea) > > def save(self): > newlog = project.objects.entry(sessionhash=sessionhash, > uniqueurl=uniqueurl) > return newlog > > And it's not working. The above is code I am trying that to avoid > complication at this stage with the relationship I was hoping would > just update one table, but the code doesn't work. I can't find > anything really detailed about saving forms that are unbound to > models. If anyone can link me something that might put me on track I'd > be grateful. > > First, I think there's some terminology confusion here. An 'unbound' form in the context of Django forms means the form has no data filled in (see: http://www.djangoproject.com/documentation/forms/#creating-form-instances), so it doesn't make any sense to 'save' an unbound form. I think what you are saying is you have a form that is not a ModelForm and so there is no database object automatically associated with the form? But you want to make some database updates based on the data in the form? If so, that's certainly possible, and you could (though I don't think you must) do it by implementing and calling a save() method for your form. save() could do the work of creating/updating the model object(s) represented in your form. It's hard to guess why what you are doing isn't working so far because 'not working' is way too vague a desciption of the problems you are running into. What exactly do you do and what happens vs. what you expect? If you provide a few more details on what 'not working' means and someone may be able to help. Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

