[Answered ]-How to Correctly Display ManyToMany ID Matching List in Django?

1👍

✅

The M-M is “wrong” you can user this
It will looks like something like this (not tested)

class User(models.Model):
    .. any data you need ..

class Car(models.Model):
    .. any data you need ..
    reservations = models.ManyToManyField(User, through='Reservations')


class Reservations(models.Model):
    car = models.ForeignKey(Car)
    user = models.ForeignKey(User)
    .. any data you need ..

You can probably place the reservations in the user and change the ref.

1👍

It’s quicker to do a query in the views.py and add the resulting queryset to the context of the view. Or use reverse by related_name. Also with the suggested through table. All you do in templates should be minimized for performance. So do the real ‘math’ in python (e.g. in the views class).

in the example given also in the comments:
https://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany

  • person is the customer
  • group is the car
  • membership is the reservation

Leave a comment