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
-~----------~----~----~----~------~----~------~--~---

Reply via email to