Monday, 9 September 2013

Django order_by last week days

Django order_by last week days

models.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
Above are my two models.I want to get total number of clicks for a
particular url_hash for last week .For example if make query today then it
should return data for the past week days only ...
Mon:2,Tue:1,Wed:10,Thu:122,Fri:97,Sat:12,Sun:11

No comments:

Post a Comment