Django

Code

Ticket #5817 (closed: fixed)

Opened 7 months ago

Last modified 3 weeks ago

Support inheritance for model option classes

Reported by: miracle2k Assigned to: nobody
Component: Core framework Version: SVN
Keywords: qs-rf-fixed Cc:
Triage Stage: Fixed on a branch Has patch: 1
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

Description

This currently is not possible:

class BaseMeta(object):
    app_label = "myapp"

class Company(models.Model):
    class Meta(BaseMeta):
        pass

The reason is that db.models.options.Options.contribute_to_class() uses __dict__ to determine which attributes have been given. It attempts to delete from __dict__, which apparently is not allowed for new-style classes, but __dict__ will not include attributes of superclasses anyway.

I attached a simple patch that uses dir() instead - if been using it for a while and there don't seem to be any problems.

Note that the patch will *not* allow custom meta attributes by prefixing them with __:

metakritik.site: 'class Meta' got invalid attribute(s): _BaseMeta__myopt

Attachments

model_meta_w_inheritance.diff (0.9 kB) - added by miracle2k on 10/25/07 08:17:41.

Change History

10/25/07 08:17:41 changed by miracle2k

  • attachment model_meta_w_inheritance.diff added.

03/02/08 10:08:09 changed by jacob

  • keywords set to qs-rf-fixed.
  • needs_better_patch changed.
  • stage changed from Unreviewed to Fixed on a branch.
  • needs_tests changed.
  • needs_docs changed.

04/26/08 21:50:16 changed by mtredinnick

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

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658


Add/Change #5817 (Support inheritance for model option classes)




Change Properties
Action