I am trying to create a trip monitoring app whereas each trip is given a ticket and particular origin and destination. What I want to do now is that given a date range, I would like to know how many trips are made for the unique origin-destination pair.
I have not found solutions to this yet and I'm hoping that somebody could enlighten me on this.
Here is my models:
class Location(models.Model)
name = models.Charfield(max_length=50, unique=True)
...
class Trip(models.Model):
ticket = models.PositiveIntegerField(primary_key=True, blank=False, null=False)
origin = models.ForeignKey(Location, on_delete=models.CASCADE)
destination = models.ForeignKey(Location, on_delete=models.CASCADE)
...
I am expecting the following output which I currently don't know what to do:
Origin | Destination | Number of Trips
Place #1 | Place #2 | 5
Place #2 | Place #1 | 3
Place #3 | Place #1 | 8
Place #3 | Place #2 | 1