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 to render the results in the template, I can't get it to work: {% for service in service_list %} <li>{{ service_list.service }}</li> {% endfor %} The template documentation says it will first try a dictionary lookup when it encounters a dot. Am I misunderstanding this? Keith On Dec 31 2007, 9:04 pm, "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.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 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.ManyToManyField(Service) > > > So, I could have hundreds of Services, but I'm only interested in > > listing the Services that have been listed in any Profile. In regards > > to the base tables, this would look like: > > > select * from app_profile_services; > > > How can I accomplish this using Django's database API? > > > Keith --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---