> > But what about 'ForeignKey's? May we pass their 'remote_name's in with > > the kwargs? > > Foreign Keys - yes. Reverse Foreign Keys - no.
Point: All kwargs takes is the fields on this object. > In the case of a foreign key, just pass in the object instance that > you want your object to be related to (e.g., when creating a Question > object, you can pass in the Poll that the question belongs to). > > > If not, what's some clean way to construct everything all at once? > > Depends on what you mean by "at once". I want to take out the objects.create, and create everything in memory. So the many-to-ones - the foreign keys - go in the kwargs. o = Model(field=x, foreigner=Foreigner()) o.manys = [ Item(), Item(), Item() ] Now everything hangs in memory like it would in the database if we created all of it. Then I want o.save() to blast it all into the database. > If you're trying to assign a list of related objects, that isn't a > single operation either - what you're actually doing is setting a > foreign key value on multiple related objects. No prob - I will just create the Item() things with a foreign key to their parent, and leave the syntactic sugar. Then I will call save() on everything from top to bottom, so all the pks populate correctly. > However, all of these are just wrappers around multiple underlying > database calls. The changes won't happen "at once" unless you start > getting involved with transactions etc. I prematurely optimize so infrequently I forgot some people use it to mean "in one database call". I just meant in one big humongous statement. No prob. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.