django模型聚集过滤器的时间不同

时间:2016-04-06 07:26:11

标签: django filter model aggregate

模型如下:

class UserInfo(models.Model):

    login_id=models.CharField(db_column='login_id',max_length=50,unique=True)
    passport_name=models.CharField(db_column='passport_name',max_length=50)
    identity_id=models.CharField(db_column='identity_id',max_length=50,null=True)
    company=models.CharField(db_column='company',max_length=50,null=True)

    ctime = models.DateTimeField(db_column='ctime', blank=True, null=True)
    utime = models.DateTimeField(db_column='utime', blank=True, null=True)
    class Meta:
        managed = True
        db_table = "user_info"


class UserViewpoint(models.Model):
    title=models.CharField(db_column='title',max_length=100)
    userid=models.ForeignKey(UserInfo,db_column='userid',to_field='login_id',related_name='rel_tg_viewpoint')
    ctime = models.DateTimeField(db_column='ctime', blank=True, null=True)
    utime = models.DateTimeField(db_column='utime', blank=True, null=True)
    class Meta:
        managed = True
        db_table = "user_viewpoint"



class UserRelationHistory(models.Model):
    """docstring for TgRelationHistory"""

    adviser_id=models.ForeignKey(UserInfo,to_field='login_id',db_column='adviser_id',related_name='rel_tg_relation_history')
    common_id=models.CharField(db_column='common_id',max_length=100)
    ctime = models.DateTimeField(db_column='ctime', blank=True, null=True)
    utime = models.DateTimeField(db_column='utime', blank=True, null=True)
    class Meta:
        managed = True
        db_table = "user_relation_history"

我想得到这样的结果: USER_ID,count_viewpoint,count_relation_new,count_relation_utilnow

count_realtion_new:user_relation.ctime在(开始,结束)

时的新实现

count_relation_utilnow:user_relation.ctime<端

1 个答案:

答案 0 :(得分:0)

在以下链接中查看此文档: https://docs.djangoproject.com/en/1.9/topics/db/

您可以使用Django ORM执行所有操作,您可以使用关系数据库执行操作。