I am noob, so this may be a simple question, but it has me stumped.
I am creating a test form so that each time the user creates a document, the date and time the document was created will be stored in the CreatedDocumentDetails model. I have not yet implemented this code yet, I am focusing on returning the count within the last 24 hours. I have inserted the values into the CreatedDocumentDetails model manually for the time being.
The issue is that I want to make a count of the documents that have been created by the user in the last 24 hours. I can return the total count of the users saved documents, but I am unsure how to write the now date & time field into the if statement to return the count of documents created in the last 24 hours.
I have the following model:
class CreatedDocumentDetails(models.Model):
user = models.ForeignKey(User)
created_document_timestamp = models.DateTimeField(auto_now_add=True, blank=True)
def __unicode__(self):
return unicode(self.user)
Here is the relevant views.py code:
def get_created_documents(user):
created_documents = len(CreatedDocumentDetails.objects.filter(user=user))
return created_documents
I am assuming that I somehow insert the now datetime field into the filter of the get_created_documents view code above.