|
|
@ -2,6 +2,7 @@
|
|
|
|
#
|
|
|
|
#
|
|
|
|
import phonenumbers
|
|
|
|
import phonenumbers
|
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
|
|
|
|
|
|
from django.db.models import Model
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from rest_framework import serializers
|
|
|
|
from rest_framework import serializers
|
|
|
|
from rest_framework.fields import ChoiceField, empty
|
|
|
|
from rest_framework.fields import ChoiceField, empty
|
|
|
@ -118,11 +119,15 @@ class ObjectRelatedField(serializers.RelatedField):
|
|
|
|
return data
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
def to_internal_value(self, data):
|
|
|
|
def to_internal_value(self, data):
|
|
|
|
|
|
|
|
queryset = self.get_queryset()
|
|
|
|
|
|
|
|
if isinstance(data, Model):
|
|
|
|
|
|
|
|
return queryset.get(pk=data.pk)
|
|
|
|
|
|
|
|
|
|
|
|
if not isinstance(data, dict):
|
|
|
|
if not isinstance(data, dict):
|
|
|
|
pk = data
|
|
|
|
pk = data
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
pk = data.get("id") or data.get("pk") or data.get(self.attrs[0])
|
|
|
|
pk = data.get("id") or data.get("pk") or data.get(self.attrs[0])
|
|
|
|
queryset = self.get_queryset()
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if isinstance(data, bool):
|
|
|
|
if isinstance(data, bool):
|
|
|
|
raise TypeError
|
|
|
|
raise TypeError
|
|
|
|