模型.py
class short_url(models.Model):
"""
This is a short_url class
"""
blocked = models.BooleanField(default=False) # To check whether URL is blocked or not
updated_at = models.DateTimeField(auto_now=True) # When URL is updated
url = models.TextField(validators=[URLValidator()]) # URL entered by the user
created_at = models.DateTimeField(auto_now_add=True) # When URL is created
url_hash = models.CharField(max_length=10,unique=True,db_index=True) # base64 encoded URL id
class click_info(models.Model):
"""
This is a click_info class
"""
user_ip = models.TextField() # Store the user_ip
user_agent = models.TextField() # Store the user_agent
http_refrer = models.TextField() # Store the http_refrer
hash = models.ForeignKey(short_url) # base64 encoded URL id
get_parameters = models.TextField() # Store other get_parameters
request_time = models.DateTimeField() # When user made the request_time
updated_at = models.DateTimeField(auto_now=True) # When click_info is updated
created_at = models.DateTimeField(auto_now_add=True) # When click is created
以上是我的两个模型。我想获得上周特定 url_hash 的点击总数。例如,如果今天进行查询,那么它应该只返回过去一周的数据......
Mon:2,Tue:1,Wed:10,Thu:122,Fri:97,Sat:12,Sun:11