Wednesday, January 27, 2016

help with ManyToMany

Hi,

I have recently returned to a Django project after a few years and I'm a little rusty on ManyToMany fields.

Here's my very simple models:


class Studio(models.Model):
    name
= models.CharField(max_length=255, unique=True)

class StudioGroup(models.Model):
    description
= models.CharField(max_length=255, unique=True)
    studio
= models.ManyToManyField(Studio)


So a bunch of Studio(), which can be in multiple StudioGroups()

Given a single instance of a Studio(), I would like a single list of all other studios in all other groups.

so if Group1 is A,B,C and Group2 is A,D,E

I would like to return B,C,D,E for A.

My current solution is entirely in Python (which works), but I'd like a more Django-esque solultion of possible!

Thank you,

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b7dff539-92ed-465c-a612-c8464724ccab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment