mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 08:14:16 +03:00
Merge branch 'master' of https://github.com/tomchristie/django-rest-framework
This commit is contained in:
commit
0beaa9bed2
|
@ -508,6 +508,25 @@ class ExclusiveFilterBackend(object):
|
||||||
return queryset.filter(text='other')
|
return queryset.filter(text='other')
|
||||||
|
|
||||||
|
|
||||||
|
class TwoFieldModel(models.Model):
|
||||||
|
field_a = models.CharField(max_length=100)
|
||||||
|
field_b = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
|
||||||
|
class DynamicSerializerView(generics.ListCreateAPIView):
|
||||||
|
model = TwoFieldModel
|
||||||
|
renderer_classes = (renderers.BrowsableAPIRenderer, renderers.JSONRenderer)
|
||||||
|
|
||||||
|
def get_serializer_class(self):
|
||||||
|
if self.request.method == 'POST':
|
||||||
|
class DynamicSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = TwoFieldModel
|
||||||
|
fields = ('field_b',)
|
||||||
|
return DynamicSerializer
|
||||||
|
return super(DynamicSerializerView, self).get_serializer_class()
|
||||||
|
|
||||||
|
|
||||||
class TestFilterBackendAppliedToViews(TestCase):
|
class TestFilterBackendAppliedToViews(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -564,28 +583,6 @@ class TestFilterBackendAppliedToViews(TestCase):
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
self.assertEqual(response.data, {'id': 1, 'text': 'foo'})
|
self.assertEqual(response.data, {'id': 1, 'text': 'foo'})
|
||||||
|
|
||||||
|
|
||||||
class TwoFieldModel(models.Model):
|
|
||||||
field_a = models.CharField(max_length=100)
|
|
||||||
field_b = models.CharField(max_length=100)
|
|
||||||
|
|
||||||
|
|
||||||
class DynamicSerializerView(generics.ListCreateAPIView):
|
|
||||||
model = TwoFieldModel
|
|
||||||
renderer_classes = (renderers.BrowsableAPIRenderer, renderers.JSONRenderer)
|
|
||||||
|
|
||||||
def get_serializer_class(self):
|
|
||||||
if self.request.method == 'POST':
|
|
||||||
class DynamicSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = TwoFieldModel
|
|
||||||
fields = ('field_b',)
|
|
||||||
return DynamicSerializer
|
|
||||||
return super(DynamicSerializerView, self).get_serializer_class()
|
|
||||||
|
|
||||||
|
|
||||||
class TestFilterBackendAppliedToViews(TestCase):
|
|
||||||
|
|
||||||
def test_dynamic_serializer_form_in_browsable_api(self):
|
def test_dynamic_serializer_form_in_browsable_api(self):
|
||||||
"""
|
"""
|
||||||
GET requests to ListCreateAPIView should return filtered list.
|
GET requests to ListCreateAPIView should return filtered list.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user