[Solved]-Django – Access fields on a model's "through" table from an instance

12👍

You can either filter on the SlideOrder model directly

slide = Slide.objects.get(pk=1)
slide_orders = SlideOrder.objects.filter(slide=slide)
for slide_order in slide_orders:
    print slide_order.number

or follow the foreign key backwards:

slide = Slide.objects.get(pk=1)
slide_orders = slide.slideorder_set.all()
for slide_order in slide_orders:
    print slide_order.number

See the docs on extra fields on many-to-many relationships for more info.

4👍

You can use slide.slideorder_set as documented in the django docs

👤Ward

Leave a comment