4 ms·
I'm the author of the feature, so I figured I should give some explanation. REQUIRED_FIELDS is used internally in one place -- in the createsuperuser managemen
by freakboy3742 14y ago
I'm the author of the feature, so I figured I should give some explanation.
REQUIRED_FIELDS is used internally in one place -- in the createsuperuser management command. When you run that command, you are prompted for the minimal set of fields to create a user object. REQUIRED_FIELDS is that list of fields.
Could this be used elsewhere? Sure. A model form, for example, could use this list as the minimal data to create a user object.
Could this be replaced with some model introspection? Possibly. On my first pass through, this is exactly what I tried to do. And the code got messy really quickly.
At a first approximation, any field with blank=False and no default is essentially "required". However, what about BooleanFields? BooleanFields have an automatically default to False, but that doesn't necessarily mean that False is an appropriate value. And what about custom fields that use the same "built-in default" pattern?
There's also a possible edge case where a field strictly isn't required (e.g., it's blankable) but from a business logic perspective, you always want to have a value.
Ultimately, I came to the conclusion that the mess was worth it. That said, I'm not 100% opposed to cleaning it up. Essentially, if someone can make createsuperuser work without the need for REQUIRED_FIELDS, and the code is robust and isn't a mess, I'm willing to look at the patch before 1.5 final. However, I'm not planning on looking at this problem myself.
- aptwebapps 14y ago"I'm the author of the feature ... " Thank you.