On Tue, May 18, 2010 at 12:45 PM, Phlip <phlip2...@gmail.com> wrote:
> Djangoists:
>
> The documentation for Model.objects.create(**kwargs) does not define
> kwargs. It just sez "kwargs".
>
> I think all of our experiences would bear out "kwargs" may at least be
> the model's fields.

Correct.

> But what about 'ForeignKey's? May we pass their 'remote_name's in with
> the kwargs?

Foreign Keys - yes. Reverse Foreign Keys - no.

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". As soon as you're dealing with
foreign keys, you're dealing with more than one database operation -
at the very least, you'll need to create or find the related objects.

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. Django doesn't provide
a single wrapper call to create *and* assign reverse foreign key
relations, but if you really want one, it won't be too hard to write.

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.

Yours,
Russ Magee %-)

-- 
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.

Reply via email to