Django model.objects.filter not working properly

So I am trying to use this

def get_queryset(self, *args, **kwargs):
        return OrderItem.objects.filter(order_id=self.kwargs['pk'])

To search my OrderItem by object and return only the ones linked to a specify order by an order_id.

However using the Django debug_toolbar I can see what the sql query is doing and it is doing the following:

SELECT "littlelemonAPI_orderitem"."id",
       "littlelemonAPI_orderitem"."order_id",
       "littlelemonAPI_orderitem"."menuitem_id",
       "littlelemonAPI_orderitem"."quantity"
  FROM "littlelemonAPI_orderitem"
 WHERE ("littlelemonAPI_orderitem"."order_id" = 2 AND "littlelemonAPI_orderitem"."id" = 2)
 LIMIT 21

In this case I passed 2 as the PK in my API endpoint but I don’t understanding why it is searching by the id when I only want it to search by the order_id.

These are my database tables:
enter image description here
enter image description here

Also these are how these two models are defined:

class Order(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    delivery_crew = models.ForeignKey(User,on_delete=models.SET_NULL,related_name='delivery_crew',null=True)
    status = models.BooleanField(db_index=True, default=0)
    total = models.DecimalField(max_digits=6,decimal_places=2)
    date = models.DateField(db_index=True,auto_now_add=True)
    
    def __str__(self):
        return f"{self.id}"

class OrderItem(models.Model):
    order = models.ForeignKey(Order, on_delete=models.CASCADEAlso)
    menuitem = models.ForeignKey(MenuItem,on_delete=models.CASCADE)
    quantity = models.SmallIntegerField()
    
    class Meta:
        unique_together = ('order','menuitem')
    
    def __str__(self):
        return f"{self.order_id}"```

And these are the serializers I am and will be using but I am not sure how these would cause this issue:

class OrderSerialzier(serializers.ModelSerializer):
user = UserSerializer
class Meta:
model = Order
fields = [‘id’,’user’,’total’,’status’,’delivery_crew’,’date’]

class OrderItemHelperSerialzier(serializers.ModelSerializer):
class Meta:
model = MenuItem
fields = [‘title’,’price’]

class OrderItemSerializer(serializers.ModelSerializer):
menuitem = OrderItemHelperSerialzier
class Meta:
model = OrderItem
fields = [‘menuitem’,’quantity’]
depth =1

class OrderAddSerializer(serializers.ModelSerializer):
class Meta:
medel =Order
fields = [‘delivery_crew’]


I haven't really tired anything  else because I cant seem to find anything about this issue online.

New contributor

john jim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật