first
This commit is contained in:
commit
89a5d70512
284 files changed
+8364
No files matched your search
@@ -0,0 +1 @@
|
||||
from .object_validation import *
|
||||
@@ -0,0 +1,26 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from django.db.models import Model
|
||||
from rest_framework import exceptions
|
||||
|
||||
class ObjectValidationABC(ABC):
|
||||
@abstractmethod
|
||||
def is_valid(self, object_id) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
class ObjectValidationById(ObjectValidationABC):
|
||||
|
||||
def __init__(self, object_model, request):
|
||||
self.object_model = object_model
|
||||
self.request = request
|
||||
|
||||
def is_valid(self, object_id) -> bool:
|
||||
try:
|
||||
result = self.object_model.objects.get(id=object_id)
|
||||
return result
|
||||
except Exception as exp:
|
||||
message = f'Error Validation object: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user