mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Use new many=True relations style.
This commit is contained in:
parent
c18fb0d695
commit
5813a09512
|
@ -470,11 +470,10 @@ class ModelSerializer(Serializer):
|
|||
# .using(db).complex_filter(self.rel.limit_choices_to)
|
||||
kwargs = {
|
||||
'required': not(model_field.null or model_field.blank),
|
||||
'queryset': model_field.rel.to._default_manager
|
||||
'queryset': model_field.rel.to._default_manager,
|
||||
'many': to_many
|
||||
}
|
||||
|
||||
if to_many:
|
||||
return ManyPrimaryKeyRelatedField(**kwargs)
|
||||
return PrimaryKeyRelatedField(**kwargs)
|
||||
|
||||
def get_field(self, model_field):
|
||||
|
@ -669,8 +668,7 @@ class HyperlinkedModelSerializer(ModelSerializer):
|
|||
kwargs = {
|
||||
'required': not(model_field.null or model_field.blank),
|
||||
'queryset': rel._default_manager,
|
||||
'view_name': self._get_default_view_name(rel)
|
||||
'view_name': self._get_default_view_name(rel),
|
||||
'many': to_many
|
||||
}
|
||||
if to_many:
|
||||
return ManyHyperlinkedRelatedField(**kwargs)
|
||||
return HyperlinkedRelatedField(**kwargs)
|
||||
|
|
|
@ -56,7 +56,7 @@ class TestGenericRelations(TestCase):
|
|||
"""
|
||||
|
||||
class BookmarkSerializer(serializers.ModelSerializer):
|
||||
tags = serializers.ManyRelatedField()
|
||||
tags = serializers.RelatedField(many=True)
|
||||
|
||||
class Meta:
|
||||
model = Bookmark
|
||||
|
|
|
@ -330,7 +330,7 @@ class ClassA(models.Model):
|
|||
|
||||
|
||||
class ClassASerializer(serializers.ModelSerializer):
|
||||
childs = serializers.ManyPrimaryKeyRelatedField(source='childs')
|
||||
childs = serializers.PrimaryKeyRelatedField(many=True, source='childs')
|
||||
|
||||
class Meta:
|
||||
model = ClassA
|
||||
|
|
|
@ -40,7 +40,7 @@ class TestManyRelateMixin(TestCase):
|
|||
|
||||
https://github.com/tomchristie/django-rest-framework/pull/632
|
||||
'''
|
||||
field = serializers.ManyRelatedField(read_only=False)
|
||||
field = serializers.RelatedField(many=True, read_only=False)
|
||||
|
||||
into = {}
|
||||
field.field_from_native({}, None, 'field_name', into)
|
||||
|
|
|
@ -20,7 +20,7 @@ urlpatterns = patterns('',
|
|||
|
||||
|
||||
class ManyToManyTargetSerializer(serializers.HyperlinkedModelSerializer):
|
||||
sources = serializers.ManyHyperlinkedRelatedField(view_name='manytomanysource-detail')
|
||||
sources = serializers.HyperlinkedRelatedField(many=True, view_name='manytomanysource-detail')
|
||||
|
||||
class Meta:
|
||||
model = ManyToManyTarget
|
||||
|
@ -32,7 +32,7 @@ class ManyToManySourceSerializer(serializers.HyperlinkedModelSerializer):
|
|||
|
||||
|
||||
class ForeignKeyTargetSerializer(serializers.HyperlinkedModelSerializer):
|
||||
sources = serializers.ManyHyperlinkedRelatedField(view_name='foreignkeysource-detail')
|
||||
sources = serializers.HyperlinkedRelatedField(many=True, view_name='foreignkeysource-detail')
|
||||
|
||||
class Meta:
|
||||
model = ForeignKeyTarget
|
||||
|
|
|
@ -16,7 +16,7 @@ class FlatForeignKeySourceSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class ForeignKeyTargetSerializer(serializers.ModelSerializer):
|
||||
sources = FlatForeignKeySourceSerializer()
|
||||
sources = FlatForeignKeySourceSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = ForeignKeyTarget
|
||||
|
|
|
@ -5,7 +5,7 @@ from rest_framework.tests.models import ManyToManyTarget, ManyToManySource, Fore
|
|||
|
||||
|
||||
class ManyToManyTargetSerializer(serializers.ModelSerializer):
|
||||
sources = serializers.ManyPrimaryKeyRelatedField()
|
||||
sources = serializers.PrimaryKeyRelatedField(many=True)
|
||||
|
||||
class Meta:
|
||||
model = ManyToManyTarget
|
||||
|
@ -17,7 +17,7 @@ class ManyToManySourceSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class ForeignKeyTargetSerializer(serializers.ModelSerializer):
|
||||
sources = serializers.ManyPrimaryKeyRelatedField()
|
||||
sources = serializers.PrimaryKeyRelatedField(many=True)
|
||||
|
||||
class Meta:
|
||||
model = ForeignKeyTarget
|
||||
|
|
|
@ -4,7 +4,7 @@ from rest_framework.tests.models import NullableForeignKeySource, ForeignKeySour
|
|||
|
||||
|
||||
class ForeignKeyTargetSerializer(serializers.ModelSerializer):
|
||||
sources = serializers.ManySlugRelatedField(slug_field='name')
|
||||
sources = serializers.SlugRelatedField(many=True, slug_field='name')
|
||||
|
||||
class Meta:
|
||||
model = ForeignKeyTarget
|
||||
|
|
|
@ -551,7 +551,7 @@ class ManyToManyTests(TestCase):
|
|||
class ReadOnlyManyToManyTests(TestCase):
|
||||
def setUp(self):
|
||||
class ReadOnlyManyToManySerializer(serializers.ModelSerializer):
|
||||
rel = serializers.ManyRelatedField(read_only=True)
|
||||
rel = serializers.RelatedField(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = ReadOnlyManyToManyModel
|
||||
|
|
Loading…
Reference in New Issue
Block a user