0
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?

1 Answer 1

1

I think I had forgotten about this:

mylist = AboutMe.objects.all().filter(MyG__in=mygpref)

This seems to work..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.