mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-06 05:20:12 +03:00
Test that meta fields cannot be declared as None
This commit is contained in:
parent
7b2124b042
commit
478fe0a394
|
@ -7,6 +7,8 @@ import re
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
from rest_framework import fields, relations, serializers
|
from rest_framework import fields, relations, serializers
|
||||||
from rest_framework.compat import unicode_repr
|
from rest_framework.compat import unicode_repr
|
||||||
from rest_framework.fields import Field
|
from rest_framework.fields import Field
|
||||||
|
@ -430,3 +432,25 @@ class TestDeclaredFieldInheritance:
|
||||||
assert len(Parent._declared_fields) == 2
|
assert len(Parent._declared_fields) == 2
|
||||||
assert len(Child._declared_fields) == 1
|
assert len(Child._declared_fields) == 1
|
||||||
assert len(Grandchild._declared_fields) == 1
|
assert len(Grandchild._declared_fields) == 1
|
||||||
|
|
||||||
|
def test_meta_field_disabling(self):
|
||||||
|
# Declaratively setting a field on a child class will *not* prevent
|
||||||
|
# the ModelSerializer from generating a default field.
|
||||||
|
class MyModel(models.Model):
|
||||||
|
f1 = models.CharField(max_length=10)
|
||||||
|
f2 = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
class Parent(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = MyModel
|
||||||
|
fields = ['f1', 'f2']
|
||||||
|
|
||||||
|
class Child(Parent):
|
||||||
|
f1 = None
|
||||||
|
|
||||||
|
class Grandchild(Child):
|
||||||
|
pass
|
||||||
|
|
||||||
|
assert len(Parent().get_fields()) == 2
|
||||||
|
assert len(Child().get_fields()) == 2
|
||||||
|
assert len(Grandchild().get_fields()) == 2
|
||||||
|
|
Loading…
Reference in New Issue
Block a user