As demonstrated 
here: https://docs.djangoproject.com/en/1.10/topics/db/examples/many_to_many/
If you have a ManyToMany relationship set up in your models, say:


class SerialNumber(models.Model):
    serial = models.CharField(max_length=50)


class Item(models.Model):
    item_name = models.CharField(max_length=100)
    serial_numbers = models.ManyToManyField(SerialNumber)


Then you can get a list of all serials for an item with:


item.serial_numbers.all()


On Thursday, November 17, 2016 at 1:26:34 PM UTC-6, Matthew Pava wrote:
>
> I am trying to annotate a list of values on a queryset.
>
> Basically, I have a model of Items that are associated many to many to 
> Serial Numbers, and I want for each distinct Item the list of all Serial 
> Numbers for that Item.
>

-- 
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+unsubscr...@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/4e58317a-4fbb-4e4f-a8c8-2e01414c679a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to