Question: I got a problem with Android Studio when I want to start a new project 
I search everywhere online and couldnt find an answer for it 

I get this error

![i get this error](https://i.stack.imgur.com/P5Gic.png)

> 
> Gradle sync failed: CreateProcess error=2, The system cannot find the file specified
>  Consult IDE log for more details (Help | Show Log) (9s 679ms)
> 
> 
>

Answer: 
You can implement some checks, in the `destroy` and return an error message as response in case the constraints are *not* met:

```
class OrderDeleteAPIView(generics.RetrieveDestroyAPIView):
    queryset = Order.objects.all()
    serializer_class = OrderDeleteSerializer
    # permission_classes = (OwnerCanManageOrReadOnly,)
    lookup_field = 'id'

     **def destroy(self, request, \*args, \*\*kwargs):
 instance = self.get\_object()
 if instance.status != Order.WAITING:
 return JsonResponse(
 status=412,
 data={'status':'false',
 'message': 'status should be WAITING'}
 )
 super(OrderDeleteAPIView, self).destroy(request, \*args, \*\*kwargs)**
```

Of course you can return any sort of answer (not *per se* a JSON response, nor does the status has to be 412). Usually HTTP status code 412 means that [**412 Precondion failed**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/412).
The question is not about permissions, but it is a close situation.

If you want to check permissions, there is a way to do this via overridden `check_permissions`:

```py
from functools import lru_cache
from rest_framework.exceptions import PermissionDenied

class OrderDeleteAPIView(generics.RetrieveDestroyAPIView):
    serializer_class = OrderDeleteSerializer
    permission_classes = (OwnerCanManageOrReadOnly,)
    lookup_field = 'id'

    @lru_cache
    def get_object(self, *args, **kwargs):
        return Order.objects.get(self.kwargs['order_id'])

    def check_permissions(self, request):
        # this method will call OwnerCanManageOrReadOnly first
        super().check_permissions(request)
        # and then do other checks
        instance = self.get_object()
        if instance.owner != request.user:
            raise PermissionDenied()

```

As you can notice, I use `@lru_cache` to cache `get_object`. The reason to use it is because after `check_permissions` there will be another method (in this case `retrieve` or `destroy`) which will call this method again. To reduce database requests count I use caching.