Tutorial ======== .. note:: This tutorial is intended for a reader that is well versed in the Django basics of the ORM, urls routing, function based views, and templates. It is also expected that you have already installed iommi in your project. Read section 1 of :ref:`Getting started `. In this tutorial you will build a discography app. By the end you will have: - an index page with album artwork - an artist page, and a page listing artists - an album page, and a page listing albums - a tracks page - the iommi admin, enabled for all of these Every step shows the code and the page it produces. Type the code in as you go; each step builds on the one before it. Set up ------ Put these models in your app's `models.py`: .. literalinclude:: models.py :pyobject: Genre :end-before: def __str__ .. literalinclude:: models.py :pyobject: Artist :end-before: def __str__ .. literalinclude:: models.py :pyobject: Album :end-before: def __str__ .. literalinclude:: models.py :pyobject: Track :end-before: def __str__ Create the tables: .. code-block:: shell python manage.py makemigrations python manage.py migrate Now load the same example data used in this tutorial, so your pages look like the screenshots. Download `big_discography.py`_ into your project and run it: .. code-block:: shell python manage.py shell < big_discography.py .. _big_discography.py: https://raw.githubusercontent.com/iommirocks/iommi/master/docs/custom/big_discography.py You're ready to build the first page. .. code-block:: python # Regenerates the example data script that the `Set up` section of this page # links to. Nothing is rendered into the docs from here. Tables ------ Creating a table view of a model in iommi is simple: .. code-block:: python urlpatterns = [ path('', Table(auto__model=Album).as_view()), ] .. raw:: html
▼ Hide result
Toggle structure
You get sorting and pagination by default, and we're using the default bootstrap 5 style. iommi ships with :ref:`more styles