getting related data from database other than default

2019-02-18 Thread progmgppers
Hi, I'm having some trouble getting data from a database with foreign-keys. Normally a query-set retrieved like this, obj = model.objects.all().filter(id=pk).select_related(), would give me the table row data, and the related row data from another table defined in the model, of the default da

Re: Getting related data...

2008-01-01 Thread ocgstyles
I just found a nice blog post: http://push.cx/2007/django-template-tag-for-dictionary-access That seems to work nicely. =) On Jan 1, 2:42 pm, ocgstyles <[EMAIL PROTECTED]> wrote: > Thanks Todd. > > I came up with this: > > def get_services(): >d = {} >for p in Profile.objects.all(): >

Re: Getting related data...

2008-01-01 Thread ocgstyles
Thanks Todd. I came up with this: def get_services(): d = {} for p in Profile.objects.all(): for s in p.services.all(): if not d.has_key(s.slug): d[s.slug] = s.name return d So I pass this function as extra context (service_list) to the template. When I try

Re: Getting related data...

2008-01-01 Thread lispingng
maybe you'll use a set on the result so you don't have duplicates, a least i think so.. On Jan 1, 2:04 am, "Todd O'Bryan" <[EMAIL PROTECTED]> wrote: > There's probably an easier/more efficient way to do it, but you can do > > services = [] > for p in Profile.objects.all(): >     services += p.ser

Re: Getting related data...

2007-12-31 Thread Todd O'Bryan
There's probably an easier/more efficient way to do it, but you can do services = [] for p in Profile.objects.all(): services += p.service_set.all() Todd On Dec 31, 2007 7:07 PM, ocgstyles <[EMAIL PROTECTED]> wrote: > > Hi All, > > I'm trying to figure out how to accomplish something using

Getting related data...

2007-12-31 Thread ocgstyles
Hi All, I'm trying to figure out how to accomplish something using Django's database API, that I can easily do with SQL. Here's my models: class Service(models.Model): name = models.CharField(max_length=50) class Profile(models.Model): user = models.ForeignKey(User) service = models.M