# Error in part 2 customizing generic views

**URL:** <https://forum.codewithmosh.com/t/error-in-part-2-customizing-generic-views/16241>\
**Category:** Django\
**Created:** [November 2, 2022, 3:46am UTC](https://forum.codewithmosh.com/t/error-in-part-2-customizing-generic-views/16241 "2022-11-02T03:46:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hosamhamdi](https://avatars.discourse-cdn.com/v4/letter/h/6bbea6/32.png) [@hosamhamdi](https://forum.codewithmosh.com/u/hosamhamdi)\
**Post date:** [November 2, 2022, 3:46am UTC](https://forum.codewithmosh.com/t/error-in-part-2-customizing-generic-views/16241/1 "2022-11-02T03:46:20Z")

</div>

i get an error after running this :

class ProductDetail(RetrieveUpdateDestroyAPIView):  
queryset=Product.objects.all()  
serializer\_class=ProductSerializer  
def delete(self,request,pk):  
product = get\_object\_or\_404(Product, pk=pk)  
if product.orderitems.count() \> 0:  
return Response({‘error’: ‘Product cannot be deleted because it is associated with an order item.’}, status=status.HTTP\_405\_METHOD\_NOT\_ALLOWED)  
product.delete()  
return Response(status=status.HTTP\_204\_NO\_CONTENT)

the error message is :  
‘Product’ object has no attribute ‘orderitems’

---

<div class="post-metadata">

**Author:** ![lassashemai](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@lassashemai](https://forum.codewithmosh.com/u/lassashemai)\
**Post date:** [November 2, 2022, 9:15am UTC](https://forum.codewithmosh.com/t/error-in-part-2-customizing-generic-views/16241/2 "2022-11-02T09:15:45Z")

</div>

![Screenshot 2022-11-02 151451](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/9/933727044cd481ff776f6cc4698773e6fa880eb3.png)

please make sure you included related\_name=‘orderitems’ in the product foreign key variable in models.py
