Re: Equivalent of find_or_create_by in Django

2009-02-17 Thread Anders
Great! Thanks. I should have known that Django of course had a function like this. Who needs Rails... A On 17 Feb, 15:11, Tim wrote: > Actually, your User example is probably more like this: > > User.objects.get_or_create(name="Bob", age=40, defaults= > {'admin'=True}) > > This tries to find a

Re: Equivalent of find_or_create_by in Django

2009-02-17 Thread Tim
Actually, your User example is probably more like this: User.objects.get_or_create(name="Bob", age=40, defaults= {'admin'=True}) This tries to find a user by name and age, then uses a default value for the admin field, but does not look up or create the user by the admin field. On Feb 17, 9:08

Re: Equivalent of find_or_create_by in Django

2009-02-17 Thread Tim
It's just as easy in Django. Tag.objects.get_or_create(name="Summer") User.objects.get_or_create(name="Bob", age=40, admin=True) On Feb 17, 8:33 am, Anders wrote: > Hi. > > I do a lot of csv-import of data and have previously been using Ruby > on Rails. And the only thing I miss about Rails (

Re: Equivalent of find_or_create_by in Django

2009-02-17 Thread Matthias Kestenholz
Hey, On Tue, Feb 17, 2009 at 2:33 PM, Anders wrote: > > Hi. > > I do a lot of csv-import of data and have previously been using Ruby > on Rails. And the only thing I miss about Rails (apart from database > migration) is the find_or_create_by methods. > > Are there any similar methods in Django?

Equivalent of find_or_create_by in Django

2009-02-17 Thread Anders
Hi. I do a lot of csv-import of data and have previously been using Ruby on Rails. And the only thing I miss about Rails (apart from database migration) is the find_or_create_by methods. Are there any similar methods in Django? My use is like this: I import a CSV file, and in one column there