Skip to content

Parser: support django-taggit TaggableManager as an M2M relation #50

Description

@FROWNINGdev

Context

django-taggit is one of the most widely used Django packages, and it is listed in awesome-django's Models section. A model using it looks like this:

class Post(models.Model):
    title = models.CharField(max_length=200)
    tags = TaggableManager()        # ← currently invisible

TaggableManager is not in the BARE_FIELD_TYPES whitelist (cli/django_orm_lens/parser.py:59), so tags is dropped: it never appears in the sidebar, the ER diagram, or describe output. Semantically it is a many-to-many to taggit.Tag through taggit.TaggedItem, so the information is genuinely useful to show.

What to change

In cli/django_orm_lens/parser.py:

  1. Add TaggableManager to BARE_FIELD_TYPES (line 59).
  2. Decide how it should surface as a relation. The natural mapping is an M2M whose target is taggit.Tag and whose through is taggit.TaggedItem_extract_through_model (line 278) already exists for the explicit through= case, so the work is supplying those defaults when the field type is TaggableManager rather than reading them from the call arguments.
  3. TaggableManager(through=CustomTaggedItem) is a real pattern — an explicit through= must win over the default.

Because taggit.Tag normally lives outside the scanned workspace, check how out-of-workspace targets are already handled: test_out_of_workspace_targets_skipped (cli/tests/test_er_formats.py:149) pins that behaviour, and whatever you do here must not break it. Deciding whether the tag target is drawn as an external node or omitted from the diagram is the main design question — say what you picked in the PR and we can discuss it there.

No taggit import and no new dependency: the parser is pure-static by design and has to work against a project with no venv at all.

Acceptance criteria

  • tags = TaggableManager() appears as an M2M field in scan / describe.
  • An explicit through= argument overrides the default.
  • Tests alongside the existing parser tests, plus an ER assertion consistent with the out-of-workspace rule above.

Getting started

pip install -e "cli[dev]"
pytest cli/tests -v -k parser

This is one half of the "third-party field support" roadmap item; django-mptt is #49.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions