Monday, January 3, 2011

Some problem with modelform save

I use modelform. All works fine. Validation is ok and I want to save my form. Before saving I need to populate user_id into my modelform so i make something like this:
if form.is_valid():
obj = form.save(commit=False)
          obj.user = request.user
          obj.save()

It seems to be ok. Form is saved to DB BUT!: I use 
categories = models.ManyToManyField(Category)

When I use the method above - categories aren't saved into DB :(
When I do form.save() - categories are added but User object not :(

Am I something missing?

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment