Get multiple rows with one query in django?

后端 未结 2 701

How can I get build a QuerySet that gets multiple rows from django? I thought filter() would work, but it seems to be worse off.

For example, I have two rows in the mode

2条回答
  •  既然无缘
    2021-02-01 17:55

    Great example. A typo I think though in your last codeblock. Should be:

    for car in Car.objects.filter(id__in=(1,2)):
        print(car.license + car.vin)
    

    How does that method stack up

提交回复
热议问题