Maybe something is missing me, but according to django docs, I can override the values ββsent from the admin form from the clean () method. From django docs
def clean(self): from django.core.exceptions import ValidationError # Don't allow draft entries to have a pub_date. if self.status == 'draft' and self.pub_date is not None: raise ValidationError('Draft entries may not have a publication date.') # Set the pub_date for published items if it hasn't been set already. if self.status == 'published' and self.pub_date is None: self.pub_date = datetime.date.today()
I deleted my code and just trying to make a basic example from inside admin
Models.py
class Test(models.Model): name = models.CharField(max_length=255,) def clean(self): self.name = 'Robin Hood' return self
Therefore, when I try to add a new test record, if I leave the name field blank, it should capture the value from the pure method and save.
What happens is that the form does not check, and the field remains empty.
Did I miss something more obvious here?
source share