Opened 2 years ago

Closed 2 years ago

#20258 closed Uncategorized (invalid)

"managed" attr of Model meta class losted during inheritance from abstract model

Reported by: vsafronovich Owned by: nobody
Component: Database layer (models, ORM) Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

class A(models.Model):
    class Meta:
        abstract = True
        managed = False

class B(A):
    pass
>>> B._meta.managed
True

must be False.

This needed for example for creating base model class for Models from legacy database.

Change History (2)

comment:1 Changed 2 years ago by vsafronovich

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

more correct example code

class A(models.Model):
    class Meta:
        abstract = True
        managed = False

class B(A):
    pass

class C(A):
    class Meta:
        db_table = 'ccc' 
>>> B._meta.managed
False
>>> C._meta.managed
True

comment:2 Changed 2 years ago by ramiro

  • Resolution set to invalid
  • Status changed from new to closed

To achieve that, make C's inner Meta class inherit from A's one::

class C(A):
    class Meta(A.Meta):
        db_table = 'ccc' 

See https://docs.djangoproject.com/en/dev/topics/db/models/#meta-inheritance

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