Coder Social home page Coder Social logo

marshalc / django-spaghetti-and-meatballs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from legostormtroopr/django-spaghetti-and-meatballs

0.0 2.0 0.0 249 KB

Its a spicy meatball for serving up fresh hot entity-relationship diagrams straight from your django models.

License: MIT License

Python 84.32% HTML 14.41% Dockerfile 1.27%

django-spaghetti-and-meatballs's Introduction

django-spaghetti-and-meatballs

Documentation Status travis Code Climate coveralls

Its a spicy meatball for serving up fresh hot entity-relationship diagrams straight from your django models.

Adding spaghetti to your project

Install some spaghetti:

pip install django-spaghetti-and-meatballs

Add "django_spaghetti" to your INSTALLED_APPS setting like this:

INSTALLED_APPS = [
    ...
    'django_spaghetti',
]

Configure your sauce

django-spaghetti-and-meatballs takes a few options set in the SPAGHETTI_SAUCE variable from your projects settings.py file that make it extra spicy:

SPAGHETTI_SAUCE = {
    'apps': ['auth', 'polls'],
    'show_fields': False,
    'exclude': {'auth': ['user']},
}

In the above dictionary, the following settings are used:

  • apps is a list of apps you want to show in the graph. If its not in here it won't be seen.
  • show_fields is a boolean that states if the field names should be shown in the graph or just in the however over. For small graphs, you can set this to True to show fields as well, but as you get more models it gets messier.
  • exclude is a dictionary where each key is an app_label and the items for that key are model names to hide in the graph.

If its not working as expected make sure your app labels and model names are all lower case.

Serve your plate in your urls file

Once you've configured your sauce, make sure you serve up a plate of spaghetti in your urls.py like so:

urlpatterns += patterns('',
    url(r'^plate/', include('django_spaghetti.urls')),
)

A sample platter

Below is an example image showing the connections between models from the django-reversion and django-notifications apps and Django's built-in auth models.

Colored edges illustrate foreign key relations, with arrows pointing from the defining model to the related model, while gray edges illustrate many-to-many relations. Different colors signify the different Django apps, and when relations link between apps the edges are colored with a gradient.

https://cloud.githubusercontent.com/assets/2173174/9053053/a45e185c-3ab2-11e5-9ea0-89dafb7ac274.png

Hovering over a model, gives a pop-up that lists the following information:

  • model name
  • app label
  • The models docstring
  • A list of every field, with its field type and its help text (if defined). Unique fields have their name underlined.

This was build with the sauce:

SPAGHETTI_SAUCE = {
    'apps': ['auth', 'notifications', 'reversion'],
    'show_fields': False,
}

A complex live-demo

To see a complex example, where django-spaghetti-and-meatballs really shines, checkout the live version built for the Aristotle Metadata Registry

Testing and developing

I like keeping my development environments isolated in docker. You can too. If you want to install poetry locally, you can skip this bit.

  • Build a container with Pythong and Poetry installed - docker build . -t spaghetti
  • Run a container for developing docker run -v "$(realpath .)":/site -w /site -p 8000:8000 -it --rm spaghetti bash
  • Install the dependencies - poetry install
  • Open a poetry shell - poetry shell
  • Run the server - django-admin runserver 0.0.0.0:8000

If you navigate to 127.0.0.1:8000 should should see the demo app.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.