Ticket #8576: multiple_autofields.diff

File multiple_autofields.diff, 1.4 KB (added by honeyman, 7 years ago)

Multiple AutoField-s

  • django/db/models/fields/__init__.py

     
    422422class AutoField(Field):
    423423    empty_strings_allowed = False
    424424    def __init__(self, *args, **kwargs):
    425         assert kwargs.get('primary_key', False) is True, "%ss must have primary_key=True." % self.__class__.__name__
    426425        kwargs['blank'] = True
    427426        Field.__init__(self, *args, **kwargs)
    428427
     
    456455        return Field.get_manipulator_new_data(self, new_data, rel)
    457456
    458457    def contribute_to_class(self, cls, name):
    459         assert not cls._meta.has_auto_field, "A model can't have more than one AutoField."
    460458        super(AutoField, self).contribute_to_class(cls, name)
    461459        cls._meta.has_auto_field = True
    462460        cls._meta.auto_field = self
  • tests/regressiontests/model_fields/models.py

     
    7878>>> Foo.objects.filter(d=u'1.23')
    7979[]
    8080
     81# Make sure it is possible to create multiple AutoFields in a model,
     82# while neither of them is a primary key.
     83>>> class MyClass(models.Model):
     84...    f1 = models.AutoField()
     85...    f2 = models.AutoField()
    8186
     87
    8288"""}
Back to Top