Django

Code

Ticket #6214 (closed: fixed)

Opened 1 year ago

Last modified 10 months ago

Small cleanup in models.base

Reported by: i_i Assigned to: nobody
Milestone: Component: Core framework
Version: SVN Keywords:
Cc: Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

fixed # TODO: Checking for the presence of '_meta' is hackish.

Attachments

models.base.diff (0.5 kB) - added by i_i on 12/18/07 22:53:12.
fixes the previous patch
optimized.models.base.diff (1.1 kB) - added by i_i on 12/24/07 14:04:32.
small optimization of previous patch
evenmoreoptimized.models.base.diff (4.6 kB) - added by i_i on 12/24/07 15:03:39.
even more optimisations
models.base-11-01-2008.diff (4.6 kB) - added by i_i on 01/11/08 14:35:54.
filter(lambda b...) changed to list comprehension

Change History

12/14/07 23:18:22 changed by i_i

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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.

12/16/07 01:48:08 changed by SmileyChris

  • stage changed from Unreviewed to Design decision needed.

Push to a design decision, since this sounds about right but such a core change needs a bit of thinking.

12/16/07 02:45:32 changed by i_i

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.

12/16/07 02:59:40 changed by i_i

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.

12/16/07 14:02:24 changed by SmileyChris

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

12/18/07 22:53:12 changed by i_i

  • attachment models.base.diff added.

fixes the previous patch

(follow-up: ↓ 7 ) 12/18/07 23:00:12 changed by i_i

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

12/24/07 14:04:32 changed by i_i

  • attachment optimized.models.base.diff added.

small optimization of previous patch

12/24/07 15:03:39 changed by i_i

  • attachment evenmoreoptimized.models.base.diff added.

even more optimisations

(in reply to: ↑ 6 ) 12/25/07 07:24:16 changed by eratothene

01/11/08 14:35:54 changed by i_i

  • attachment models.base-11-01-2008.diff added.

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

02/08/08 06:01:24 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #6214 (Small cleanup in models.base)




Change Properties
Action