I am noob, so this may be a simple question, but it puzzles me.
I create a test form so that every time the user creates the document, the date and time the document was created will be stored in the CreatedDocumentDetails model. I have not implemented this code yet, I am focused on returning the account within the last 24 hours. I currently inserted values ββinto the CreatedDocumentDetails model manually.
The problem is that I want to count the documents that were created by the user in the last 24 hours. I can return the total score of saved documents, but I donβt know how to write the current date and time field to the if statement in order to return the number 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 corresponding views.py code:
def get_created_documents(user): created_documents = len(CreatedDocumentDetails.objects.filter(user=user)) return created_documents
I assume that somehow I am now inserting the datetime field into the filter of the get_created_documents code described above.
source share