myprefs = aboutme.mypreferences_set.all()[0]
mygpref = myprefs.MyGPref.all()
mygpref has a range of values and I'd like to return a QuerySet based on on these filters. I don't know how many values there may be in mygprefs. Might be one or two. How should I build a filter the pythonic way without lots of if and thens - I tried the below but this does not work for multiple values exist in mygpref.
mylist = AboutMe.objects.all().filter(MyG=mygpref)
How to do this elegantly?
I think I had forgotten about this:
mylist = AboutMe.objects.all().filter(MyG__in=mygpref)
This seems to work..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.