Make a django query with a list of parameter [duplicate]










1
















This question already has an answer here:



  • django filter with list of values

    3 answers



i have a list of id like :



ids = [1,2,3]


Is there a quicker way to do a query for all of them than a for ?
Like:



users = 
for id in ids :
users.append(User.objects.get(id=id))


thanks










share|improve this question













marked as duplicate by Community Nov 14 '18 at 19:07


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















    1
















    This question already has an answer here:



    • django filter with list of values

      3 answers



    i have a list of id like :



    ids = [1,2,3]


    Is there a quicker way to do a query for all of them than a for ?
    Like:



    users = 
    for id in ids :
    users.append(User.objects.get(id=id))


    thanks










    share|improve this question













    marked as duplicate by Community Nov 14 '18 at 19:07


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















      1












      1








      1









      This question already has an answer here:



      • django filter with list of values

        3 answers



      i have a list of id like :



      ids = [1,2,3]


      Is there a quicker way to do a query for all of them than a for ?
      Like:



      users = 
      for id in ids :
      users.append(User.objects.get(id=id))


      thanks










      share|improve this question















      This question already has an answer here:



      • django filter with list of values

        3 answers



      i have a list of id like :



      ids = [1,2,3]


      Is there a quicker way to do a query for all of them than a for ?
      Like:



      users = 
      for id in ids :
      users.append(User.objects.get(id=id))


      thanks





      This question already has an answer here:



      • django filter with list of values

        3 answers







      python django django-queryset






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 14:24









      user462794user462794

      21631950




      21631950




      marked as duplicate by Community Nov 14 '18 at 19:07


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Community Nov 14 '18 at 19:07


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          1 Answer
          1






          active

          oldest

          votes


















          3














          Yes, use the __in filter function:



          users = User.objects.filter(id__in=ids)





          share|improve this answer































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            Yes, use the __in filter function:



            users = User.objects.filter(id__in=ids)





            share|improve this answer





























              3














              Yes, use the __in filter function:



              users = User.objects.filter(id__in=ids)





              share|improve this answer



























                3












                3








                3







                Yes, use the __in filter function:



                users = User.objects.filter(id__in=ids)





                share|improve this answer















                Yes, use the __in filter function:



                users = User.objects.filter(id__in=ids)






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 14 '18 at 15:21

























                answered Nov 14 '18 at 14:25









                schwobasegglschwobaseggl

                37.2k32442




                37.2k32442















                    這個網誌中的熱門文章

                    What does pagestruct do in Eviews?

                    Dutch intervention in Lombok and Karangasem

                    Channel Islands