Thursday, October 15, 2009

Re: question about foreign key

Hi jul,

if there is a chance that the country doesn't exist you have to check
that before.
Have a look at get_or_create:
http://docs.djangoproject.com/en/dev/ref/models/querysets/#get-or-create-kwargs

Cheers, Till

On Oct 15, 1:51 pm, jul <juj...@gmail.com> wrote:
> Hi,
>
> I've got the two models Country and Restaurant shown below. Is there a
> way to directly set a country by instanciating a restaurant with a
> Country instance? Something like:
>
> r=Restaurant(name='whatever', country=Country(name='newcountry'))
> r.save()
>
> which returns "Column 'country_id' cannot be null"
>
> Or do I have to previously check if the country exists, and creating
> it if it doesn't?
>
> Thanks
> jul

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate