如果我有一个模型表格并保存如下:
f = FormModel(request.POST)
if f.is_valid():
f.save()
Run Code Online (Sandbox Code Playgroud)
我怎样才能找回刚刚保存的对象?
如何在Django中创建自定义字段查找?
当过滤查询集,Django提供了一组您可以使用查找的:__contains
,__iexact
,__in
,等等.我希望能够为我的经理提供新的查找,例如,有人可以说:
twentysomethings = Person.objects.filter(age__within5=25)
Run Code Online (Sandbox Code Playgroud)
并获取Person
年龄在20到30之间的所有对象.我是否需要继承QuerySet
或Manager
类来执行此操作?如何实施?
我很茫然.我一直试图让这个工作好几天了.但我没有得到这个,所以我想我会在这里咨询你们,看看有人能帮助我!
我正在使用pyparsing试图将一种查询格式解析为另一种查询格式.这不是一个简单的转变,但实际上需要一些大脑:)
当前查询如下:
("breast neoplasms"[MeSH Terms] OR breast cancer[Acknowledgments]
OR breast cancer[Figure/Table Caption] OR breast cancer[Section Title]
OR breast cancer[Body - All Words] OR breast cancer[Title]
OR breast cancer[Abstract] OR breast cancer[Journal])
AND (prevention[Acknowledgments] OR prevention[Figure/Table Caption]
OR prevention[Section Title] OR prevention[Body - All Words]
OR prevention[Title] OR prevention[Abstract])
Run Code Online (Sandbox Code Playgroud)
使用pyparsing我已经能够得到以下结构:
[[[['"', 'breast', 'neoplasms', '"'], ['MeSH', 'Terms']], 'or',
[['breast', 'cancer'], ['Acknowledgments']], 'or', [['breast', 'cancer'],
['Figure/Table', 'Caption']], 'or', [['breast', 'cancer'], ['Section',
'Title']], 'or', [['breast', 'cancer'], ['Body', '-', 'All', 'Words']],
'or', [['breast', 'cancer'], …
Run Code Online (Sandbox Code Playgroud)