On Tue, Feb 8, 2011 at 12:32 PM, NavaTux <navaneetha...@gmail.com> wrote: > Thanks Tom > mjob=Job.objects.create(name=name,city=city,tags=tag) > > Here i shouldn't use to create a object for foreign key and many_to_many > field; we have to get it from it's id right? because the key property > violates then, > city=City.objects.get(id=city_id) > tag=Tag.objects.get(id=tag_id) > mjob=Job.objects.create(name=name,city=city,tags=tag) > > it seems also problem!!
If you refer to the documentation I linked to[1] """ add(obj1[, obj2, ...])ΒΆ Adds the specified model objects to the related object set. Example: >>> b = Blog.objects.get(id=1) >>> e = Entry.objects.get(id=234) >>> b.entry_set.add(e) # Associates Entry e with Blog b. """ Please go read the documentation. You do not create M2M links by passing them to the object constructor, you add them to the object post construction. Cheers Tom [1] http://docs.djangoproject.com/en/1.2/ref/models/relations/ -- 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.