Saving related model objects
- by iHeartDucks
I have two related models (one to many) in my django app and When I do something like this
ObjBlog = Blog()
objBlog.name = 'test blog'
objEntry1 = Entry()
objEntry1.title = 'Entry one'
objEntry2 = Entry()
objEntry2.title = 'Entry Two'
objBlog.entry_set.add(objEntry1)
objBlog.entry_set.add(objEntry2)
I get an error which says "null value in column and it violates the foreign key not null constraint".
None of my model objects have been saved. Do I have to save the "objBlog" before I could set the entries? I was hoping I could call the save method on objBlog to save it all.
NOTE: I am not creating a blog engine and this is just an example.