mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Merge 3fc1b13217
into 411511622d
This commit is contained in:
commit
fa9079a542
|
@ -55,6 +55,10 @@ class ManyToManyModel(RESTFrameworkModel):
|
||||||
rel = models.ManyToManyField(Anchor, help_text='Some help text.')
|
rel = models.ManyToManyField(Anchor, help_text='Some help text.')
|
||||||
|
|
||||||
|
|
||||||
|
class ManyToManyModelTwo(RESTFrameworkModel):
|
||||||
|
rel = models.ManyToManyField(Anchor, null=True, blank=True, help_text='Some other help text.')
|
||||||
|
|
||||||
|
|
||||||
class ReadOnlyManyToManyModel(RESTFrameworkModel):
|
class ReadOnlyManyToManyModel(RESTFrameworkModel):
|
||||||
text = models.CharField(max_length=100, default='anchor')
|
text = models.CharField(max_length=100, default='anchor')
|
||||||
rel = models.ManyToManyField(Anchor)
|
rel = models.ManyToManyField(Anchor)
|
||||||
|
|
|
@ -10,7 +10,7 @@ from rest_framework import serializers, fields, relations
|
||||||
from tests.models import (
|
from tests.models import (
|
||||||
HasPositiveIntegerAsChoice, Album, ActionItem, Anchor, BasicModel,
|
HasPositiveIntegerAsChoice, Album, ActionItem, Anchor, BasicModel,
|
||||||
BlankFieldModel, BlogPost, BlogPostComment, Book, CallableDefaultValueModel,
|
BlankFieldModel, BlogPost, BlogPostComment, Book, CallableDefaultValueModel,
|
||||||
DefaultValueModel, ManyToManyModel, Person, ReadOnlyManyToManyModel, Photo,
|
DefaultValueModel, ManyToManyModel, ManyToManyModelTwo, Person, ReadOnlyManyToManyModel, Photo,
|
||||||
RESTFrameworkModel, ForeignKeySource
|
RESTFrameworkModel, ForeignKeySource
|
||||||
)
|
)
|
||||||
from tests.models import BasicModelSerializer
|
from tests.models import BasicModelSerializer
|
||||||
|
@ -757,6 +757,34 @@ class MetadataTests(TestCase):
|
||||||
self.assertTrue(isinstance(serializer.data.fields[field_name], field))
|
self.assertTrue(isinstance(serializer.data.fields[field_name], field))
|
||||||
|
|
||||||
|
|
||||||
|
class ManyToManyTwoTests(TestCase):
|
||||||
|
"""
|
||||||
|
Tests model with a ManyToMany relationship with field attributes
|
||||||
|
null==True and blank==True.
|
||||||
|
"""
|
||||||
|
def setUp(self):
|
||||||
|
class ManyToManySerializerTwo(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = ManyToManyModelTwo
|
||||||
|
|
||||||
|
self.serializer_class = ManyToManySerializerTwo
|
||||||
|
|
||||||
|
# An anchor instance to use for the relationship
|
||||||
|
self.anchor = Anchor()
|
||||||
|
self.anchor.save()
|
||||||
|
|
||||||
|
def test_create(self):
|
||||||
|
"""
|
||||||
|
Create an instance of a model with a ManyToMany relationship.
|
||||||
|
"""
|
||||||
|
data = {'rel': [self.anchor.id]}
|
||||||
|
serializer = self.serializer_class(data=data)
|
||||||
|
self.assertEqual(serializer.is_valid(), True)
|
||||||
|
instance = serializer.save()
|
||||||
|
self.assertEqual(ManyToManyModelTwo.objects.count(), 1)
|
||||||
|
self.assertEqual(list(instance.rel.all()), [self.anchor])
|
||||||
|
|
||||||
|
|
||||||
class ManyToManyTests(TestCase):
|
class ManyToManyTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
class ManyToManySerializer(serializers.ModelSerializer):
|
class ManyToManySerializer(serializers.ModelSerializer):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user