Check this example, but they are using a customized form for models:
http://www.djangobook.com/en/2.0/chapter14/#cn176
If your form is not derived from your model, you'll want to explicitly
create the model object:
def yourview(request):
if request.method == 'POST':
form = YourForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
# assuming your html widgets have the same name as the
fields in your model and your pk increments automatically
your_model = YourModel(cr=cd['cr'], description=cd
['description'], file=cd['file'])
# the following line will save the data to the db
your_model.save()
On May 18, 6:08 pm, jon michaels <[email protected]> wrote:
> Hi all,
>
> I have the a from with the following validated data posted to itself
> (copied from the POST section on the error page):
>
> cr u'008'
> description u'asdfs'
> file u'suus'
>
> I am trying to save it to the database. The variable names are the
> same as the column names in the database. How can i go about this? I
> tried various things with .save(), but that didn't work yet.
> I also tried doing it using cursor.execute (with only one value for a
> start) but that resulted in the error ''unicode' object has no
> attribute 'items''. I used this statement:
>
> cursor.execute("insert cr into editor.conffile values('%s')", cd['cr'])
>
> The following failed with "global name 'cr' is not defined"
> cursor.execute("insert cr into editor.conffile values('%s')", cr)
>
> Thanks in advance for your help!
>
> Jon.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---