I have created a model named Flight which is connected to another model named Passengers
flights = models.ManyToManyField(Flight, blank=True, related_name="passengers")
i tried to use Passengers = Flight.Passengers.all() it throws an error saying that
Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: 'ManyToManyDescriptor' object has no attribute 'all'
need help with it!
i want only the realted fields from flight and passengers into my html but it throw an error whenever i try to access using Flight.Passengers.all() and Flight.Passengers.get()
it can be bypass using Passengers.objects.all() but i don't need that otherwise there will be no relation between my databases!
That makes perfect sense, the
related_nameworks with aFlightobject, not theFlightclass, what would that even mean?You thus fetch a
Flightobject:and then you get the passengers of the
my_flightwith:It does not work with the
Flightclass, the only sensical response for that would be returning allPassengers that have at least one flight. You can do that with: