Opened 18 years ago
Closed 18 years ago
#6214 closed (fixed)
Small cleanup in models.base
| Reported by: | Ivan Illarionov | Owned by: | nobody | 
|---|---|---|---|
| Component: | Core (Other) | Version: | dev | 
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Design decision needed | |
| Has patch: | yes | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
fixed # TODO: Checking for the presence of '_meta' is hackish.
Attachments (4)
Change History (12)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
| Triage Stage: | Unreviewed → Design decision needed | 
|---|
Push to a design decision, since this sounds about right but such a core change needs a bit of thinking.
comment:3 by , 18 years ago
I can also suggest the renaming of the first argument of ModelBase.__new__ from cls to metacls for clarity, because it really is a ModelBase metaclass. It can be a source of confusion  in future development and for people trying to understand what's happening since it's not clear from the code that cls here is NOT a newly created Model or Model-based class.
Oh, and ModelBase can be renamed to something like _ModelMetaclass because it is not a BASE class for Model it is a CLASS of Model class. And with first underscore if it is not intended for importing or customization.
comment:4 by , 18 years ago
And, if we are talking about the design decision, I would also note that classmethods of Model (add_to_class and _prepare) can be safely moved to its metaclass as normal (not class) methods. It has the advantage of separating the logic of Model classes and Model instances.
comment:5 by , 18 years ago
Perhaps you could try to get a discussion going in the django-dev group.
follow-up: 7 comment:6 by , 18 years ago
I mistakenly thought that only Model subclasses can be in bases. New patch fixes this.
by , 18 years ago
| Attachment: | optimized.models.base.diff added | 
|---|
small optimization of previous patch
comment:7 by , 18 years ago
Link to the discussion:
http://groups.google.com/group/django-developers/browse_thread/thread/0073b756f35b2030?hl=en
by , 18 years ago
| Attachment: | models.base-11-01-2008.diff added | 
|---|
filter(lambda b...) changed to list comprehension
comment:8 by , 18 years ago
| Resolution: | → fixed | 
|---|---|
| Status: | new → closed | 
Since each base can only be a Model subclass it always has the same metaclass and therefore always has a
_metaattribute except the Model class itself.