On 20 jul, 10:53, james_027 <[EMAIL PROTECTED]> wrote:
> hi,
>
> is there a short cut for assigning input data to model's data
> attribute?
>
> if Book is a model then
>
> b = Book(request.POST)
> b.save()
>
> the assignment will be done on all the match key of  the request.POST
> QueryDict and data attribute of the Book Model.
>
> or
>
> if BookForm is a newform then
>
> bf = BookForm()
> if bf.is_valid():
>     b = Book(bf.cleaned_data)
>
> thanks
> james

You could run through the request.POST's keys and assign them to the
Model's attributes:
b = Book()
for key in request.POST.keys():
---b.__setattribute__(key, request.POST[key])
b.save()


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to