获取自上次登录以来创建的所有Django记录 [英] Get all Django records created since last login
问题描述
使用Django模型,是否有一个过滤器可以用来选择在特定日期之后创建的所有记录?我不知道我应该使用什么语法或过滤器来获取比last_login更新的所有记录。
我不介意使用Q高级查询,但是
实际上,如果要选择所有记录,则不需要当前的日期时间一定的日期只需使用一个如下所示的查找过滤器:field_date__gte = last_login。这里没有必要使用范围。例如:
MyModel.objects.filter(my_model_date__gte = last_login)
pre>
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!
解决方案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)
这篇关于获取自上次登录以来创建的所有Django记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!