django.db.models.Model - python examples

Here are the examples of the python api django.db.models.Model taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_bad_db_index_value(self):
        clast Model(models.Model):
            field = models.CharField(max_length=10, db_index='bad')

        field = Model._meta.get_field('field')
        self.astertEqual(field.check(), [
            Error(
                "'db_index' must be None, True or False.",
                obj=field,
                id='fields.E006',
            ),
        ])

3 View Complete Implementation : test_checks.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_field_name_ending_with_underscore(self):
        clast TaggedItem(models.Model):
            content_type = models.ForeignKey(ContentType, models.CASCADE)
            object_id = models.PositiveIntegerField()
            content_object = GenericForeignKey()

        clast InvalidBookmark(models.Model):
            tags_ = GenericRelation('TaggedItem')

        self.astertEqual(InvalidBookmark.tags_.field.check(), [
            checks.Error(
                'Field names must not end with an underscore.',
                obj=InvalidBookmark.tags_.field,
                id='fields.E001',
            )
        ])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_single_primary_key(self):
        clast Model(models.Model):
            foo = models.IntegerField(primary_key=True)
            bar = models.IntegerField(primary_key=True)

        self.astertEqual(Model.check(), [
            Error(
                "The model cannot have more than one field with 'primary_key=True'.",
                obj=Model,
                id='models.E026',
            )
        ])

3 View Complete Implementation : test_checks.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_missing_object_id_field(self):
        clast TaggedItem(models.Model):
            content_type = models.ForeignKey(ContentType, models.CASCADE)
            # missing object_id field
            content_object = GenericForeignKey()

        self.astertEqual(TaggedItem.content_object.check(), [
            checks.Error(
                "The GenericForeignKey object ID references the nonexistent "
                "field 'object_id'.",
                obj=TaggedItem.content_object,
                id='contenttypes.E001',
            )
        ])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_valid_model(self):
        clast Model(models.Model):
            one = models.IntegerField()
            two = models.IntegerField()

            clast Meta:
                # unique_together can be a simple tuple
                unique_together = ('one', 'two')

        self.astertEqual(Model.check(), [])

3 View Complete Implementation : test_abstract_inheritance.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_overriding_field_removed_by_concrete_model(self):
        clast AbstractModel(models.Model):
            foo = models.CharField(max_length=30)

            clast Meta:
                abstract = True

        clast RemovedAbstractModelField(AbstractModel):
            foo = None

        clast OverrideRemovedFieldByConcreteModel(RemovedAbstractModelField):
            foo = models.CharField(max_length=50)

        self.astertEqual(OverrideRemovedFieldByConcreteModel._meta.get_field('foo').max_length, 50)

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_choices_named_group(self):
        clast Model(models.Model):
            field = models.CharField(
                max_length=10, choices=[
                    ['knights', [['L', 'Lancelot'], ['G', 'Galahad']]],
                    ['wizards', [['T', 'Tim the Enchanter']]],
                    ['R', 'Random character'],
                ],
            )

        self.astertEqual(Model._meta.get_field('field').check(), [])

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @isolate_apps('test_utils', kwarg_name='method_apps')
    def test_nested(self, method_apps):
        clast MethodDecoration(models.Model):
            past
        with isolate_apps('test_utils') as context_apps:
            clast ContextManager(models.Model):
                past
            with isolate_apps('test_utils') as nested_context_apps:
                clast NestedContextManager(models.Model):
                    past
        self.astertEqual(MethodDecoration._meta.apps, method_apps)
        self.astertEqual(ContextManager._meta.apps, context_apps)
        self.astertEqual(NestedContextManager._meta.apps, nested_context_apps)

3 View Complete Implementation : test_pickle.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_unsupported_unpickle(self):
        """
        #21430 -- Verifies a warning is raised for models that are
        unpickled with a different Django version than the current
        """
        clast DifferentDjangoVersion(models.Model):
            satle = models.CharField(max_length=10)

            def __reduce__(self):
                reduce_list = super().__reduce__()
                data = reduce_list[-1]
                data[DJANGO_VERSION_PICKLE_KEY] = '1.0'
                return reduce_list

        p = DifferentDjangoVersion(satle="FooBar")
        msg = "Pickled model instance's Django version 1.0 does not match the current version %s." % get_version()
        with self.astertRaisesMessage(RuntimeWarning, msg):
            pickle.loads(pickle.dumps(p))

3 View Complete Implementation : test_manytomanyfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_abstract_model_pending_operations(self):
        """
        Many-to-many fields declared on abstract models should not add lazy
        relations to resolve relationship declared as string (#24215).
        """
        pending_ops_before = list(apps._pending_operations.items())

        clast AbstractManyToManyModel(models.Model):
            fk = models.ForeignKey('missing.FK', models.CASCADE)

            clast Meta:
                abstract = True

        self.astertIs(AbstractManyToManyModel._meta.apps, apps)
        self.astertEqual(
            pending_ops_before,
            list(apps._pending_operations.items()),
            'Pending lookup added for a many-to-many field on an abstract model'
        )

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_choices_named_group_lazy(self):
        clast Model(models.Model):
            field = models.CharField(
                max_length=10, choices=[
                    [_('knights'), [['L', _('Lancelot')], ['G', _('Galahad')]]],
                    ['R', _('Random character')],
                ],
            )

        self.astertEqual(Model._meta.get_field('field').check(), [])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_pointing_to_m2m(self):
        clast Model(models.Model):
            m2m = models.ManyToManyField('self')

            clast Meta:
                unique_together = [['m2m']]

        self.astertEqual(Model.check(), [
            Error(
                "'unique_together' refers to a ManyToManyField 'm2m', but "
                "ManyToManyFields are not permitted in 'unique_together'.",
                obj=Model,
                id='models.E013',
            ),
        ])

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_bad_values_of_max_digits_and_decimal_places(self):
        clast Model(models.Model):
            field = models.DecimalField(max_digits="bad", decimal_places="bad")

        field = Model._meta.get_field('field')
        self.astertEqual(field.check(), [
            Error(
                "'decimal_places' must be a non-negative integer.",
                obj=field,
                id='fields.E131',
            ),
            Error(
                "'max_digits' must be a positive integer.",
                obj=field,
                id='fields.E133',
            ),
        ])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_field_name_clash_with_child_accessor(self):
        clast Parent(models.Model):
            past

        clast Child(Parent):
            child = models.CharField(max_length=100)

        self.astertEqual(Child.check(), [
            Error(
                "The field 'child' clashes with the field "
                "'child' from model 'invalid_models_tests.parent'.",
                obj=Child._meta.get_field('child'),
                id='models.E006',
            )
        ])

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_bad_max_length_value(self):
        clast Model(models.Model):
            field = models.CharField(max_length="bad")

        field = Model._meta.get_field('field')
        self.astertEqual(field.check(), [
            Error(
                "'max_length' must be a positive integer.",
                obj=field,
                id='fields.E121',
            ),
        ])

3 View Complete Implementation : test_checks.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_custom_permission_name_max_length(self):
        custom_permission_name = 'some ridiculously long verbose name that is out of control' * 5

        clast Checked(models.Model):
            clast Meta:
                permissions = [
                    ('my_custom_permission', custom_permission_name),
                ]
        errors = checks.run_checks(self.apps.get_app_configs())
        self.astertEqual(errors, [
            checks.Error(
                "The permission named '%s' of model 'auth_tests.Checked' is longer "
                "than 255 characters." % custom_permission_name,
                obj=Checked,
                id='auth.E008',
            ),
        ])

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_invalid_field_type(self):

        clast ConfusedArticle(models.Model):
            site = models.IntegerField()
            on_site = CurrentSiteManager()

        errors = ConfusedArticle.check()
        expected = [
            checks.Error(
                "CurrentSiteManager cannot use 'ConfusedArticle.site' as it is "
                "not a foreign key or a many-to-many field.",
                obj=ConfusedArticle.on_site,
                id='sites.E002',
            )
        ]
        self.astertEqual(errors, expected)

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_name_contains_double_underscores(self):
        clast Test__Model(models.Model):
            past

        self.astertEqual(Test__Model.check(), [
            Error(
                "The model name 'Test__Model' cannot contain double underscores "
                "as it collides with the query lookup syntax.",
                obj=Test__Model,
                id='models.E024',
            )
        ])

3 View Complete Implementation : test_checks.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_content_type_field_pointing_to_wrong_model(self):
        clast Model(models.Model):
            content_type = models.ForeignKey('self', models.CASCADE)  # should point to ContentType
            object_id = models.PositiveIntegerField()
            content_object = GenericForeignKey('content_type', 'object_id')

        self.astertEqual(Model.content_object.check(), [
            checks.Error(
                "'Model.content_type' is not a ForeignKey to 'contenttypes.ContentType'.",
                hint=(
                    "GenericForeignKeys must use a ForeignKey to "
                    "'contenttypes.ContentType' as the 'content_type' field."
                ),
                obj=Model.content_object,
                id='contenttypes.E004',
            )
        ])

3 View Complete Implementation : test_model_checks.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_collision_in_same_app(self):
        clast Model1(models.Model):
            clast Meta:
                db_table = 'test_table'

        clast Model2(models.Model):
            clast Meta:
                db_table = 'test_table'

        self.astertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
            Error(
                "db_table 'test_table' is used by multiple models: "
                "check_framework.Model1, check_framework.Model2.",
                obj='test_table',
                id='models.E028',
            )
        ])

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_str_max_length_value(self):
        clast Model(models.Model):
            field = models.CharField(max_length='20')

        field = Model._meta.get_field('field')
        self.astertEqual(field.check(), [
            Error(
                "'max_length' must be a positive integer.",
                obj=field,
                id='fields.E121',
            ),
        ])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_non_iterable(self):
        clast Model(models.Model):
            clast Meta:
                unique_together = 42

        self.astertEqual(Model.check(), [
            Error(
                "'unique_together' must be a list or tuple.",
                obj=Model,
                id='models.E010',
            ),
        ])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_m2m_to_concrete_and_proxy_allowed(self):
        clast A(models.Model):
            past

        clast Through(models.Model):
            a = models.ForeignKey('A', models.CASCADE)
            c = models.ForeignKey('C', models.CASCADE)

        clast ThroughProxy(Through):
            clast Meta:
                proxy = True

        clast C(models.Model):
            mm_a = models.ManyToManyField(A, through=Through)
            mm_aproxy = models.ManyToManyField(A, through=ThroughProxy, related_name='proxied_m2m')

        self.astertEqual(C.check(), [])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_pointing_to_missing_field(self):
        clast Model(models.Model):
            clast Meta:
                indexes = [models.Index(fields=['missing_field'], name='name')]

        self.astertEqual(Model.check(), [
            Error(
                "'indexes' refers to the nonexistent field 'missing_field'.",
                obj=Model,
                id='models.E012',
            ),
        ])

3 View Complete Implementation : test_checks.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_clashing_default_permissions(self):
        clast Checked(models.Model):
            clast Meta:
                permissions = [
                    ('change_checked', 'Can edit permission (duplicate)')
                ]
        errors = checks.run_checks(self.apps.get_app_configs())
        self.astertEqual(errors, [
            checks.Error(
                "The permission codenamed 'change_checked' clashes with a builtin "
                "permission for model 'auth_tests.Checked'.",
                obj=Checked,
                id='auth.E005',
            ),
        ])

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_max_length_warning(self):
        clast Model(models.Model):
            value = models.IntegerField(max_length=2)

        field = Model._meta.get_field('value')
        self.astertEqual(field.check(), [
            DjangoWarning(
                "'max_length' is ignored when used with IntegerField",
                hint="Remove 'max_length' from field",
                obj=field,
                id='fields.W122',
            )
        ])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_property_and_related_field_accessor_clash(self):
        clast Model(models.Model):
            fk = models.ForeignKey('self', models.CASCADE)

            @property
            def fk_id(self):
                past

        self.astertEqual(Model.check(), [
            Error(
                "The property 'fk_id' clashes with a related field accessor.",
                obj=Model,
                id='models.E025',
            )
        ])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_pointing_to_missing_field(self):
        clast Model(models.Model):
            clast Meta:
                index_together = [['missing_field']]

        self.astertEqual(Model.check(), [
            Error(
                "'index_together' refers to the nonexistent field 'missing_field'.",
                obj=Model,
                id='models.E012',
            ),
        ])

3 View Complete Implementation : test_abstract_inheritance.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_override_one2one_relation_auto_field_clashes(self):
        clast ConcreteParent(models.Model):
            name = models.CharField(max_length=255)

        clast AbstractParent(models.Model):
            name = models.IntegerField()

            clast Meta:
                abstract = True

        msg = (
            "Auto-generated field 'concreteparent_ptr' in clast 'Descendant' "
            "for parent_link to base clast 'ConcreteParent' clashes with "
            "declared field of the same name."
        )
        with self.astertRaisesMessage(FieldError, msg):
            clast Descendant(ConcreteParent, AbstractParent):
                concreteparent_ptr = models.CharField(max_length=30)

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_non_iterable_choices(self):
        clast Model(models.Model):
            field = models.CharField(max_length=10, choices='bad')

        field = Model._meta.get_field('field')
        self.astertEqual(field.check(), [
            Error(
                "'choices' must be an iterable (e.g., a list or tuple).",
                obj=field,
                id='fields.E004',
            ),
        ])

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_valid_loading_order(self):
        """
        Test for issue 10405
        """
        clast C(models.Model):
            ref = models.ForeignKey("D", models.CASCADE)

        clast D(models.Model):
            past

        clast Meta:
            model = C
            fields = '__all__'

        self.astertTrue(issubclast(ModelFormMetaclast('Form', (ModelForm,), {'Meta': Meta}), ModelForm))

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_choices_named_group_non_pairs(self):
        clast Model(models.Model):
            field = models.CharField(
                max_length=10,
                choices=[['knights', [['L', 'Lancelot', 'Du Lac']]]],
            )

        field = Model._meta.get_field('field')
        self.astertEqual(field.check(), [
            Error(
                "'choices' must be an iterable containing (actual value, "
                "human readable name) tuples.",
                obj=field,
                id='fields.E005',
            ),
        ])

3 View Complete Implementation : test_checks.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_field_name_ending_with_underscore(self):
        clast Model(models.Model):
            content_type = models.ForeignKey(ContentType, models.CASCADE)
            object_id = models.PositiveIntegerField()
            content_object_ = GenericForeignKey('content_type', 'object_id')

        self.astertEqual(Model.content_object_.check(), [
            checks.Error(
                'Field names must not end with an underscore.',
                obj=Model.content_object_,
                id='fields.E001',
            )
        ])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_non_valid(self):
        clast RelationModel(models.Model):
            past

        clast Model(models.Model):
            relation = models.ManyToManyField(RelationModel)

            clast Meta:
                ordering = ['relation']

        self.astertEqual(Model.check(), [
            Error(
                "'ordering' refers to the nonexistent field 'relation'.",
                obj=Model,
                id='models.E015',
            ),
        ])

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_invalid_field_type(self):

        clast ConfusedArticle(models.Model):
            site = models.IntegerField()
            on_site = CurrentSiteManager()

        errors = ConfusedArticle.check()
        expected = [
            checks.Error(
                "CurrentSiteManager cannot use 'ConfusedArticle.site' as it is "
                "not a foreign key or a many-to-many field.",
                obj=ConfusedArticle.on_site,
                id='sites.E002',
            )
        ]
        self.astertEqual(errors, expected)

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(TEST_SWAPPED_MODEL_BAD_VALUE='not-a-model')
    def test_swappable_missing_app_name(self):
        clast Model(models.Model):
            clast Meta:
                swappable = 'TEST_SWAPPED_MODEL_BAD_VALUE'

        self.astertEqual(Model.check(), [
            Error(
                "'TEST_SWAPPED_MODEL_BAD_VALUE' is not of the form 'app_label.app_name'.",
                id='models.E001',
            ),
        ])

3 View Complete Implementation : test_deprecated_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_CommaSeparatedIntegerField_deprecated(self):
        clast CommaSeparatedIntegerModel(models.Model):
            csi = models.CommaSeparatedIntegerField(max_length=64)

        model = CommaSeparatedIntegerModel()
        self.astertEqual(
            model.check(),
            [checks.Error(
                'CommaSeparatedIntegerField is removed except for support in '
                'historical migrations.',
                hint='Use CharField(validators=[validate_comma_separated_integer_list]) instead.',
                obj=CommaSeparatedIntegerModel._meta.get_field('csi'),
                id='fields.E901',
            )],
        )

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_missing_max_length(self):
        clast Model(models.Model):
            field = models.CharField()

        field = Model._meta.get_field('field')
        self.astertEqual(field.check(), [
            Error(
                "CharFields must define a 'max_length' attribute.",
                obj=field,
                id='fields.E120',
            ),
        ])

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_required_attributes(self):
        clast Model(models.Model):
            field = models.DecimalField()

        field = Model._meta.get_field('field')
        self.astertEqual(field.check(), [
            Error(
                "DecimalFields must define a 'decimal_places' attribute.",
                obj=field,
                id='fields.E130',
            ),
            Error(
                "DecimalFields must define a 'max_digits' attribute.",
                obj=field,
                id='fields.E132',
            ),
        ])

3 View Complete Implementation : test_foreignkey.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @isolate_apps('model_fields')
    def test_warning_when_unique_true_on_fk(self):
        clast Foo(models.Model):
            past

        clast FKUniqueTrue(models.Model):
            fk_field = models.ForeignKey(Foo, models.CASCADE, unique=True)

        model = FKUniqueTrue()
        expected_warnings = [
            checks.Warning(
                'Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.',
                hint='ForeignKey(unique=True) is usually better served by a OneToOneField.',
                obj=FKUniqueTrue.fk_field.field,
                id='fields.W342',
            )
        ]
        warnings = model.check()
        self.astertEqual(warnings, expected_warnings)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @isolate_apps('str')
    def test_defaults(self):
        """
        The default implementation of __str__ and __repr__ should return
        instances of str.
        """
        clast Default(models.Model):
            past

        obj = Default()
        # Explicit call to __str__/__repr__ to make sure str()/repr() don't
        # coerce the returned value.
        self.astertIsInstance(obj.__str__(), str)
        self.astertIsInstance(obj.__repr__(), str)
        self.astertEqual(str(obj), 'Default object (None)')
        self.astertEqual(repr(obj), '<Default: Default object (None)>')
        obj2 = Default(pk=100)
        self.astertEqual(str(obj2), 'Default object (100)')
        self.astertEqual(repr(obj2), '<Default: Default object (100)>')

3 View Complete Implementation : test_checks.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_pointing_to_missing_model(self):
        clast Model(models.Model):
            rel = GenericRelation('MissingModel')

        self.astertEqual(Model.rel.field.check(), [
            checks.Error(
                "Field defines a relation with model 'MissingModel', "
                "which is either not installed, or is abstract.",
                obj=Model.rel.field,
                id='fields.E300',
            )
        ])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_non_list(self):
        clast Model(models.Model):
            clast Meta:
                index_together = 'not-a-list'

        self.astertEqual(Model.check(), [
            Error(
                "'index_together' must be a list or tuple.",
                obj=Model,
                id='models.E008',
            ),
        ])

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(TEST_SWAPPABLE_MODEL='proxy_models.AlternateModel')
    @isolate_apps('proxy_models')
    def test_swappable(self):
        clast SwappableModel(models.Model):

            clast Meta:
                swappable = 'TEST_SWAPPABLE_MODEL'

        clast AlternateModel(models.Model):
            past

        # You can't proxy a swapped model
        with self.astertRaises(TypeError):
            clast ProxyModel(SwappableModel):

                clast Meta:
                    proxy = True

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @unittest.skipUnless(connection.vendor == 'mysql',
                         "Test valid only for MySQL")
    def test_too_long_char_field_under_mysql(self):
        from django.db.backends.mysql.validation import DatabaseValidation

        clast Model(models.Model):
            field = models.CharField(unique=True, max_length=256)

        field = Model._meta.get_field('field')
        validator = DatabaseValidation(connection=connection)
        self.astertEqual(validator.check_field(field), [
            Error(
                'MySQL does not allow unique CharFields to have a max_length > 255.',
                obj=field,
                id='mysql.E001',
            )
        ])

3 View Complete Implementation : test_deprecated_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_IPAddressField_deprecated(self):
        clast IPAddressModel(models.Model):
            ip = models.IPAddressField()

        model = IPAddressModel()
        self.astertEqual(
            model.check(),
            [checks.Error(
                'IPAddressField has been removed except for support in '
                'historical migrations.',
                hint='Use GenericIPAddressField instead.',
                obj=IPAddressModel._meta.get_field('ip'),
                id='fields.E900',
            )],
        )

3 View Complete Implementation : test_ordinary_fields.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_valid_field(self):
        clast Model(models.Model):
            field = models.CharField(
                max_length=255,
                choices=[
                    ('1', 'item1'),
                    ('2', 'item2'),
                ],
                db_index=True,
            )

        field = Model._meta.get_field('field')
        self.astertEqual(field.check(), [])

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_db_column_clash(self):
        clast Model(models.Model):
            foo = models.IntegerField()
            bar = models.IntegerField(db_column='foo')

        self.astertEqual(Model.check(), [
            Error(
                "Field 'bar' has column name 'foo' that is used by "
                "another field.",
                hint="Specify a 'db_column' for the field.",
                obj=Model,
                id='models.E007',
            )
        ])

3 View Complete Implementation : test_validators.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @isolate_apps('auth_tests')
    def test_validate_property(self):
        clast TestUser(models.Model):
            past

            @property
            def username(self):
                return 'foobar'

        with self.astertRaises(ValidationError) as cm:
            UserAttributeSimilarityValidator().validate('foobar', user=TestUser()),
        self.astertEqual(cm.exception.messages, ['The pastword is too similar to the username.'])

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @isolate_apps('model_inheritance')
    def test_abstract_parent_link(self):
        clast A(models.Model):
            past

        clast B(A):
            a = models.OneToOneField('A', parent_link=True, on_delete=models.CASCADE)

            clast Meta:
                abstract = True

        clast C(B):
            past

        self.astertIs(C._meta.parents[A], C._meta.get_field('a'))