0

this is my model and i'm using postgresql:

class TripRequest(models.Model):
    ...
    passenger = models.ForeignKey('user.Passenger', on_delete=models.DO_NOTHING)
    beginning_point = models.PointField()
    beginning_locality = models.CharField(max_length=50, null=True)
    destination_point = models.PointField()
    destination_locality = models.CharField(max_length=50, null=True)
    ...

how can i group all records that have matching beginning_locality and matching destination_locality?

mahyar
  • 539
  • 1
  • 4
  • 12

1 Answers1

0

If I understand what you want to achieve, with filter, you can specify as many filters you want; As in:

TripRequest.objects.filter(beginning_locality='somevalue', destination_locality='another_value')
Pedram Parsian
  • 3,750
  • 3
  • 19
  • 34
  • thanks for your answer but this will work if i have values for beginning and destination. but i want to group all existing records in db – mahyar Nov 26 '19 at 11:45
  • 1
    Do you want all the `TripRequest` objects grouped by their `beginning_locality` and `destination_locality`? Check out [this](https://stackoverflow.com/a/629691/9733868) – Pedram Parsian Nov 26 '19 at 11:50