Filter by ForeignKey reference??

2009-02-02 Thread Markus T.
Hi, I have two simple models: class Country(models.Model): name = models.CharField(_("Name"), max_length=50, unique=True) class Profile(models.Model): name = models.CharField(_("Name"), max_length=50, unique=True) country = models.ForeignKey(Country) If I want to

Re: Filter by ForeignKey reference??

2009-02-02 Thread Martin Conte Mac Donell
On Mon, Feb 2, 2009 at 10:11 PM, Markus T. wrote: > > Hi, > > I have two simple models: > > class Country(models.Model): > name = models.CharField(_("Name"), max_length=50, > unique=True) > > class Profile(models.Model): > name = models.CharField(_("Name"), max_length=50, > un

Re: Filter by ForeignKey reference??

2009-02-02 Thread Martin Conte Mac Donell
On Mon, Feb 2, 2009 at 11:59 PM, Martin Conte Mac Donell wrote: > If you need country_id/country_name: > Profile.objects.values('country__id', 'country__name').select_related('country').distinct() > [{'country__name': u'Country1', 'country__id': 1}, {'country__name': > u'Country3', 'co

Re: Filter by ForeignKey reference??

2009-02-03 Thread Markus T.
Thanks for your reply! Your approach returns a list of dictionaries (or tuples if values_list () is used). Do you know of a straight forward way that returns a list of model objects, like filter() or all()? (I mean something smarter than looping the returned list of tuples and creating a new list

Re: Filter by ForeignKey reference??

2009-02-03 Thread Rajesh Dhawan
> I have two simple models: > > class Country(models.Model): > name = models.CharField(_("Name"), max_length=50, > unique=True) > > class Profile(models.Model): > name = models.CharField(_("Name"), max_length=50, > unique=True) > country = models.ForeignKey(Country) >

Re: Filter by ForeignKey reference??

2009-02-10 Thread Markus T.
That's it - thanks a lot!!! --~--~-~--~~~---~--~~ 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 djang