0

Using django need to return a query set where values should be IN variable p1 and p2 :

p1 = 's'
p2 = 't'
formset_OK=pocketTransactionFormset(queryset=Pockets.objects.filter(pocket_owner=request.user).extra(where=['pocket_name=%s'], params=[p1]))

the above code with formset_OK works but then it will result in only 1 value i.e. s , however i want to have values using IN Clause of SQL, so i tried below code but it dosent work and throws error no such column: s :

formset_NOTOK =pocketTransactionFormset(queryset=Pockets.objects.filter(pocket_owner=request.user).extra(where=['pocket_name IN (s,t)']))

Django documentation says that

Entry.objects.extra(where=['id IN (3, 4, 5, 20)'])

is equal to

SELECT * FROM blog_entry WHERE id IN (3, 4, 5, 20);

but seems this is not true when 3,4,5,6 are strings .

ANy advices how to make it work for strings :

paarth batra
  • 1,392
  • 4
  • 29
  • 53

1 Answers1

0

my mistake posted question too early found easy way to deal this using

formset = pocketTransactionFormset(queryset=Pockets.objects.filter(pocket_owner=request.user).filter(pocket_name__in=[p1,p2]))
paarth batra
  • 1,392
  • 4
  • 29
  • 53