Skip to main content

a library traversing django models

Project description

  • (todo: gentle introduction)

  • (todo: add information about use case)


  • collecting information about dependencies of models (model -> parent)

  • collecting information about reverse dependencies of models (model -> [children])

  • listing model with dependencies-considered order.

(dependencies-considered order means, when i < j, models[i] doesn’t depends on models[j])

how to use

from django_mindscape import ModelMapProvider, Walker, Brain
from django.apps import apps

walker = Walker(apps.get_models(), brain=Brain(), bidirection=False)
p = ModelMapProvider(walker)

when ParentModel : YourModel = 1 : N
and OtherModel is existed.

# model dependencies (bottom up)
for relation in p.dependencies[YourModel].dependencies:
    print(relation.from_.model)  # <YourModel>
    print(  # <ParentModel>
    print(relation.type)  # relation type (candidates: 11, 1M, MM)

# reverse dependencies (top down)
for rnode in p.reverse_dependencies[ParentModel].children:
    print(rnode.node.model)  # <YourModel>

# clustered model list
for cluster in p.cluster_models:  # [[ParentModel, YourModel], [OtherModel]]
    for model in cluster:

# ordered model list
for model in p.ordered_models:  # [ParentModel, YourModel, OtherModel]

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-mindscape-0.1.2.tar.gz (4.8 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page