Collin Grady wrote:
> David Cramer said the following:
>> I don't believe .create() allows you to say myforeignkey=1, correct me
>> if I'm wrong, but I think it throws an error about it needing to be a
>> <ForeigNkeyClass> instance.

Yes, you are correct.

> But .create() already works with fkeyname_id, it's just get() and
> get_or_create() that don't :)

I say you are looking at it backwards here.  It's not that get() and
get_or_create() don't work with fkeyname_id, it's that Model() and create()
don't work with fkeyname.

To take the examples in the ticket description:
==============
MyModel.objects.create(author_id=1) # Works

but it shouldn't.  Instead, we should make the following allowed:
MyModel.objects.create(author=1)
MyModel.objects.create(author='1')
--------------
MyModel.objects.create(author=Author(id=1)) # Works

This is a tricky way around django.db.models.base.Model.__init__'s current
enforcement of the foreign key field (without the _id) wanting an instance,
but shouldn't be needed if we implement the above (meaning create() would act
like get() in that you could pass either an int, a str, or a model instance to
the foreign key field).
==============
MyModel.objects.get(author_id=1) # Doesn't Work

as it shouldn't.
--------------
MyModel.objects.get(author=Author(id=1)) # Works

as it should, but sort of pointless since foreign key field in get() can
already take an int or str too.
--------------
MyModel.objects.get_or_create(author_id=1) # Doesn't Work

as it shouldn't.  But, the following should be made to work:
MyModel.objects.get_or_create(author=1)
MyModel.objects.get_or_create(author='1')
MyModel.objects.get_or_create(..., defaults={'author': 1})
MyModel.objects.get_or_create(..., defaults={'author': '1'})
And they would work if django.db.models.base.Model.__init__ is fixed as
mentioned above with create().
--------------

Gary

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to