How to get bellow by using django ORM
myset = {2, 3}
I need names from field 'name' that have '2'&'3' only in 'value' field:
class Mytable(models.Model):
name = models.CharField(max_length=45, blank=True, null=True)
value = models.CharField(max_length=45, blank=True, null=True)
Table in DB (model.Mytable)
'name'|'value'
--------------
'Ann' |'2'
'Ann' |'3'
'Ann' |'5'
'John'|'2'
'John'|'3'
'Jim' |'3'
'Jim' |'2'
'Pit' |'7'
'Pit' |'8'
Needed output: ['John', 'Jim'] # value '2','3' only
So, I try to get construction like:
QuerySet [('Ann', ['2','3','5']), ('John', ['2', '3']), ...
using .annotatte()
, .values()
But i don't know how get it using Django ORM.
Or i can use some filter in .filters()
?
question from:
https://stackoverflow.com/questions/66049246/use-django-orm-to-take-values-from-field-that-have-some-set-of-values-in-enother 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…