Context
Models built on django-mptt are currently invisible to the parser — not merely missing a field, but skipped entirely.
_looks_like_model (cli/django_orm_lens/parser.py:358) decides whether a class is a Django model from its base classes. It accepts models.Model, a handful of common abstract names, anything matching Abstract[A-Z], and anything ending in Mixin. MPTTModel matches none of them, so:
class Category(MPTTModel): # skipped — never appears in the sidebar,
name = models.CharField(max_length=50) # ER diagram, or any analyzer
parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True)
The second half of the problem is TreeForeignKey / TreeOneToOneField / TreeManyToManyField. These are thin subclasses of the corresponding Django fields, but the parser matches field types against the literal whitelist in BARE_FIELD_TYPES (parser.py:59) and relations against RELATION_TYPES (parser.py:38), so even inside a detected model they would be dropped.
What to change
- Teach
_looks_like_model about MPTTModel (and MPTTMeta-style bases if you find others worth adding).
- Add the three
Tree* field names to BARE_FIELD_TYPES and to RELATION_TYPES, so _extract_related / _extract_on_delete / _extract_related_name (lines 221–278) treat them exactly like their Django counterparts. TreeForeignKey('self', ...) must produce the same self-referential edge that a plain ForeignKey('self', ...) does — there is already a test for the self-FK case at cli/tests/test_er_formats.py:112.
Please keep this additive: no django-mptt import, no new dependency. The parser is deliberately pure-static and must keep working on a project whose venv is broken.
Acceptance criteria
- A model inheriting
MPTTModel shows up in django-orm-lens scan with its fields.
TreeForeignKey('self', ...) renders a self-edge in er, honouring on_delete and related_name.
- A fixture under
cli/tests/fixtures/ covering both, wired into the test suite.
Getting started
pip install -e "cli[dev]"
pytest cli/tests -v -k parser
Note this is one half of the "third-party field support" roadmap item; django-taggit is tracked separately in #50 — feel free to take either or both.
Context
Models built on django-mptt are currently invisible to the parser — not merely missing a field, but skipped entirely.
_looks_like_model(cli/django_orm_lens/parser.py:358) decides whether a class is a Django model from its base classes. It acceptsmodels.Model, a handful of common abstract names, anything matchingAbstract[A-Z], and anything ending inMixin.MPTTModelmatches none of them, so:The second half of the problem is
TreeForeignKey/TreeOneToOneField/TreeManyToManyField. These are thin subclasses of the corresponding Django fields, but the parser matches field types against the literal whitelist inBARE_FIELD_TYPES(parser.py:59) and relations againstRELATION_TYPES(parser.py:38), so even inside a detected model they would be dropped.What to change
_looks_like_modelaboutMPTTModel(andMPTTMeta-style bases if you find others worth adding).Tree*field names toBARE_FIELD_TYPESand toRELATION_TYPES, so_extract_related/_extract_on_delete/_extract_related_name(lines 221–278) treat them exactly like their Django counterparts.TreeForeignKey('self', ...)must produce the same self-referential edge that a plainForeignKey('self', ...)does — there is already a test for the self-FK case atcli/tests/test_er_formats.py:112.Please keep this additive: no
django-mpttimport, no new dependency. The parser is deliberately pure-static and must keep working on a project whose venv is broken.Acceptance criteria
MPTTModelshows up indjango-orm-lens scanwith its fields.TreeForeignKey('self', ...)renders a self-edge iner, honouringon_deleteandrelated_name.cli/tests/fixtures/covering both, wired into the test suite.Getting started
pip install -e "cli[dev]" pytest cli/tests -v -k parserNote this is one half of the "third-party field support" roadmap item; django-taggit is tracked separately in #50 — feel free to take either or both.