Search code examples
djangomodelsrecords

Get all Django records created since last login


Using Django models, is there a filter I can use to select all records created after a certain date? I'm not sure what syntax or filter I should use to get all records newer than my last_login.

I wouldn't mind doing it with a Q advanced query, but the simpler the better!


Solution

  • Actually, you don't need the current datetime if you want to select all records created after a certain date. Just use a filter with a lookup like: field_date__gte=last_login. It's not necessary to use range here. For example:

    MyModel.objects.filter(my_model_date__gte=last_login)