ORM does not work this way.
Item.product
is of type Product
and item in OrderItem
is of type Item
If you want to get Item from slug field on Product
, you need to access related object reference using __
(double underscore) in filter condition.
item = Items.objects.filter(product__slug=slug).first()
order_item, created = OrderItem.objects.get_or_create(item=item, account=request.user, ordered=False)
.first() is used because, filter returns QuerySet