Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

python - How to emulate Postgres Django distinct() with SQLite backend

I'm racking my brain on how to form this filter query using Django's Querysets. The following filter query returns objects containing the following fields: candidate, informationField, option.

selected_options = CandidateInformationListOptionsAnswer.objects.filter(
    candidate=candidate, informationField=element
)

In selected_option, every object will have the same values for candidate and informationField. However, the option fields in the objects in the QuerySet have duplicates, when they should instead be unique.

Therefore, I want to run the equivalent of a .distinct("option") call on selected_options, but my DB backend is not Postgres, so I don't have the ability to pass in field names into a QuerySet.distinct() call.

How would I structure my .filter() queries to get a QuerySet of objects that are distinct for a particular field with a SQLite backend?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...