【问题标题】:how to group all records with multiple matching fields如何对具有多个匹配字段的所有记录进行分组
【发布时间】:2019-11-26 11:12:02
【问题描述】:

这是我的模型,我正在使用 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)
    ...

如何将所有匹配beginning_locality 和匹配destination_locality 的记录分组?

【问题讨论】:

    标签: django postgresql django-orm


    【解决方案1】:

    如果我了解您想要实现的目标,使用filter,您可以指定任意数量的过滤器;如:

    TripRequest.objects.filter(beginning_locality='somevalue', destination_locality='another_value')
    

    【讨论】:

    • 感谢您的回答,但如果我有起点和终点的值,这将起作用。但我想对数据库中的所有现有记录进行分组
    • 您想要将所有TripRequest 对象按其beginning_localitydestination_locality 分组吗?查看this
    猜你喜欢
    • 2021-07-26
    • 2020-09-16
    • 2021-09-11
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多