Opened 16 years ago

Closed 16 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)

models.base.diff (528 bytes ) - added by Ivan Illarionov 16 years ago.
fixes the previous patch
optimized.models.base.diff (1.1 KB ) - added by Ivan Illarionov 16 years ago.
small optimization of previous patch
evenmoreoptimized.models.base.diff (4.6 KB ) - added by Ivan Illarionov 16 years ago.
even more optimisations
models.base-11-01-2008.diff (4.6 KB ) - added by Ivan Illarionov 16 years ago.
filter(lambda b...) changed to list comprehension

Download all attachments as: .zip

Change History (12)

comment:1 by Ivan Illarionov, 16 years ago

Since each base can only be a Model subclass it always has the same metaclass and therefore always has a _meta attribute except the Model class itself.

comment:2 by Chris Beaven, 16 years ago

Triage Stage: UnreviewedDesign 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 Ivan Illarionov, 16 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 Ivan Illarionov, 16 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 Chris Beaven, 16 years ago

Perhaps you could try to get a discussion going in the django-dev group.

by Ivan Illarionov, 16 years ago

Attachment: models.base.diff added

fixes the previous patch

comment:6 by Ivan Illarionov, 16 years ago

I mistakenly thought that only Model subclasses can be in bases. New patch fixes this.

by Ivan Illarionov, 16 years ago

Attachment: optimized.models.base.diff added

small optimization of previous patch

by Ivan Illarionov, 16 years ago

even more optimisations

by Ivan Illarionov, 16 years ago

Attachment: models.base-11-01-2008.diff added

filter(lambda b...) changed to list comprehension

comment:8 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [7098]) Fixed #6214 -- Added some small optimisations to model class initialisation.
Thanks, Ivan Illarionov.

Note: See TracTickets for help on using tickets.
Back to Top