|
@@ -5,6 +5,7 @@ import pytz
|
|
|
|
|
|
from django.conf import settings
|
|
from django.conf import settings
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
+from django.db.models import ManyToManyField
|
|
from django.http import Http404
|
|
from django.http import Http404
|
|
from rest_framework import mixins
|
|
from rest_framework import mixins
|
|
from rest_framework.exceptions import APIException
|
|
from rest_framework.exceptions import APIException
|
|
@@ -51,6 +52,11 @@ class ValidatedModelSerializer(ModelSerializer):
|
|
|
|
|
|
# Run clean() on an instance of the model
|
|
# Run clean() on an instance of the model
|
|
if self.instance is None:
|
|
if self.instance is None:
|
|
|
|
+ model = self.Meta.model
|
|
|
|
+ # Ignore ManyToManyFields for new instances (a PK is needed for validation)
|
|
|
|
+ for field in model._meta.get_fields():
|
|
|
|
+ if isinstance(field, ManyToManyField):
|
|
|
|
+ attrs.pop(field.name)
|
|
instance = self.Meta.model(**attrs)
|
|
instance = self.Meta.model(**attrs)
|
|
else:
|
|
else:
|
|
instance = self.instance
|
|
instance = self.instance
|