Ticket #8576: multiple_autofields.diff
File multiple_autofields.diff, 1.4 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/__init__.py
422 422 class AutoField(Field): 423 423 empty_strings_allowed = False 424 424 def __init__(self, *args, **kwargs): 425 assert kwargs.get('primary_key', False) is True, "%ss must have primary_key=True." % self.__class__.__name__426 425 kwargs['blank'] = True 427 426 Field.__init__(self, *args, **kwargs) 428 427 … … 456 455 return Field.get_manipulator_new_data(self, new_data, rel) 457 456 458 457 def contribute_to_class(self, cls, name): 459 assert not cls._meta.has_auto_field, "A model can't have more than one AutoField."460 458 super(AutoField, self).contribute_to_class(cls, name) 461 459 cls._meta.has_auto_field = True 462 460 cls._meta.auto_field = self -
tests/regressiontests/model_fields/models.py
78 78 >>> Foo.objects.filter(d=u'1.23') 79 79 [] 80 80 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() 81 86 87 82 88 """}