views:

46

answers:

1
A: 

I would guess that one of your models has a Foreign Key field which is not nullable. When you do objBlog.entry_set.add(objEntry1) django calls save() on each object.

This is how the add method looks like:

def add(self, *objs):
    for obj in objs:
        if not isinstance(obj, self.model):
            raise TypeError("'%s' instance expected" % self.model._meta.object_name)
        setattr(obj, rel_field.name, instance)
        obj.save()
add.alters_data = True
rebus
so I have to save the blog object before I could save the entry object?
iHeartDucks
It gets saved automatically, how do your models look like? Django is probably complaining because there is a FK relation to a model other then `Blog` and `Entry` on one or both of them which can not be null. Actual traceback would be helpful for providing actual help or at least the actual exception.
rebus
I had to save the Blog object first. I guess, I thought Django would save the Blog object first and then save the Entry objects. When I say "save", I do objBlog.save() and then I do this objBlog.entry_set.add(objEntry). Now I know that I have to save the parent object first.
iHeartDucks