File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 7
7
8
8
import pytest
9
9
10
+ from django .db import models
11
+
10
12
from rest_framework import fields , relations , serializers
11
13
from rest_framework .compat import unicode_repr
12
14
from rest_framework .fields import Field
@@ -430,3 +432,25 @@ class Grandchild(Child):
430
432
assert len (Parent ._declared_fields ) == 2
431
433
assert len (Child ._declared_fields ) == 1
432
434
assert len (Grandchild ._declared_fields ) == 1
435
+
436
+ def test_meta_field_disabling (self ):
437
+ # Declaratively setting a field on a child class will *not* prevent
438
+ # the ModelSerializer from generating a default field.
439
+ class MyModel (models .Model ):
440
+ f1 = models .CharField (max_length = 10 )
441
+ f2 = models .CharField (max_length = 10 )
442
+
443
+ class Parent (serializers .ModelSerializer ):
444
+ class Meta :
445
+ model = MyModel
446
+ fields = ['f1' , 'f2' ]
447
+
448
+ class Child (Parent ):
449
+ f1 = None
450
+
451
+ class Grandchild (Child ):
452
+ pass
453
+
454
+ assert len (Parent ().get_fields ()) == 2
455
+ assert len (Child ().get_fields ()) == 2
456
+ assert len (Grandchild ().get_fields ()) == 2
You can’t perform that action at this time.
0 commit comments