unexpected admin behavior for field when submitting "blank" and altering in model.save()
|Reported by:||pragmar||Owned by:||Honza_Kral|
|Severity:||Keywords:||model, save, blank, not null|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Today updated from trunk revision 12007 to 1.2 alpha (r12114) and discovered an oddity in the admin - the behavior disappeared after reverting back to 12007 with no other changes applied.
Here's the basic setup:
There's a model with a DateTimeField named "publish" and blank set to True. I've implemented without auto_now_add, but the intended behavior is similar as there's a save method that looks to populate if it is submitted blank. To lend some perspective, the reason it is set up in this manner is to allow a simple admin ui (it's tucked into an advanced collapsible) while maintaining the potential to publish to the future.
class Post(KeenerBase): publish = models.DateTimeField('publish',blank=True) ... def save(self, *args, **kwargs): if not self.publish: self.publish = datetime.datetime.utcnow() super(Post, self).save(*args, **kwargs)
Under 12007 a blank publish field falls through to the Post.save(), adds the datetime and validates. Under 1.2 alpha it does not validate and doesn't appear to hit the save method. The admin validation states the field can not be null. The release notes didn't mention anything regarding model changes to that effect, so I beleive I may've hit a bug.
Change History (4)
comment:1 Changed 7 years ago by pragmar
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 7 years ago by Honza_Kral
- milestone set to 1.2
- Owner changed from nobody to Honza_Kral
- Triage Stage changed from Unreviewed to Design decision needed
comment:3 Changed 7 years ago by jkocherhans
- Resolution set to fixed
- Status changed from new to closed