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 wrote:
> Hi,
>
> I've got the two models Country and Res
On Oct 15, 1:46 pm, bruno desthuilliers
wrote:
> On 15 oct, 13:51, jul 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(nam
On 15 oct, 13:51, jul 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()
>
3 matches
Mail list logo