I have a model with a charfield serving as primary key. While creating an instance (through admin panel) everything is fine and my clean method works ok too. But if I come back to update myfield than not only clean method fails to catch non-numeric characters, but the whole instance is duplicated. One with old myfield value and the new one with altered myfield.
# models.py
class Mymodel(models.Model):
myfield = models.CharField(primary_key=True, max_length=10)
...
def clean(self):
if not re.match(r'[0-9]+', self.pesel):
raise ValidationError('Digits only.', code='invalid')
super(Mymodel, self).clean()
How can I fix this? I need it to be a primary key and I need it to be editable. And extra issue with this clean not functioning well, I think it may be connected. I'm Django 1.5.5