小编pet*_*lux的帖子

Django聚合.extra值

模型,带抽象基类:

class MapObject(models.Model):
    start_date = models.DateTimeField(default= datetime.strptime('1940-09-01T00:00:00',  '%Y-%m-%dT%H:%M:%S'))
    end_date = models.DateTimeField(default= datetime.strptime('1941-07-01T00:00:00',  '%Y-%m-%dT%H:%M:%S'))
    description = models.TextField(blank=True)
    location = models.PointField()
    objects = models.GeoManager()
    user = models.ForeignKey(User)
    created = models.DateTimeField(auto_now_add = True)
    last_modified = models.DateTimeField(auto_now = True)
    source = models.ForeignKey(Source)
    address= models.TextField(blank=True, null=True)
    address_road = models.TextField(blank=True, null=True)

class Meta:
    abstract = True

class Bomb(MapObject, BombExtraManager):
    #Bomb Attributes
    type = models.CharField(choices= Type_CHOICES, max_length=10)
    night_bombing = models.BooleanField(blank=True)
    map_sheet = models.ForeignKey(MapSheet, blank=True, null=True)
    def __unicode__(self):
        return self.type
Run Code Online (Sandbox Code Playgroud)

现在,我希望使用Django ORM获得与此查询相同的结果:

Select date_part('day',"start_date") as "day", date_part('hour',"start_date") as …
Run Code Online (Sandbox Code Playgroud)

django orm aggregate

1
推荐指数
1
解决办法
4081
查看次数

标签 统计

aggregate ×1

django ×1

orm ×1