# django-material **Repository Path**: mirrors_un33k/django-material ## Basic Information - **Project Name**: django-material - **Description**: Material Design for django forms and admin - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-26 - **Last Updated**: 2026-11-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README =============== Django Material =============== Material design for Django Forms and Admin. Template driven. .. image:: https://travis-ci.org/viewflow/django-material.svg :target: https://travis-ci.org/viewflow/django-material .. image:: https://badges.gitter.im/Join%20Chat.svg :alt: Join the chat at https://gitter.im/viewflow/django-material :target: https://gitter.im/viewflow/django-material?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge Overview ======== - Forms_ - new way to render django forms * Strong python/html code separation * Easy redefinition of particular fields rendering * Complex form layout support - Frontend_ - Quick starter template for modular ERP-like applications developent - Admin_ - Material-designed django admin Demo: http://forms.viewflow.io/ .. image:: .screen.png :width: 400px Installation ============ django-material tested with Python 2.7/3.3, django 1.8:: pip install django-material Forms ===== Add `material` into INSTALLED_APPS settings .. code-block:: python INSTALLED_APPS = ( 'material', ... ) Include material javascript and styles into your base template. .. code-block:: html {% include 'material/includes/material_css.html' %} {% include 'material/includes/material_js.html' %} Load the `material_form` template tag library .. code-block:: html {% load material_form %} And render your form with {% form %} template tag .. code-block:: html
Template tags ------------- `django-material` forms processing is built around simple concept called *part*. `part` is like django template block, it has a default value and could be overriden. But `parts` are created dynamically for each form field, which allows you to redefine specific form field html render output. Here is the example of rendering form with but prefix email field with email icon. .. code-block:: html There is a lot of other parts declared in default templates. See template code for details. If your widget is so special, you can completly override its rendering .. code-block:: html {% part form.my_field %}any html code here{% endpart %} Layout ------ Layout object is the way to specify relative fields placements and sizes. .. code-block:: python from material import * layout = Layout( Row('shipment_no', 'description') Fieldset("Add to inventory", Row(Span3('product_name'), 'tags'), Row('vendor', 'product_type'), Row(Column('sku', 'stock_level', span_columns=4), 'gender', 'desired_gender'), Row('cost_price', Span2('wholesale_price'), 'retail_price'))) SpanXX elements are not to material grid classes, but used to determine relative fields width. Each row occupies 12 grid columns. Elements in Row('elem1', 'elem2') would be rendered in 6 grid coulmns each, and in Row(Span2('elem1'), 'elem2') `elem1` would be rendered in 8 grid columns, and `elem2` in 4 grid columns. Layouts rendering itself is specified in template. ModelForm Views --------------- Material forms library provides LayoutMixin for model form views, populates form fields list directly from layout object .. code-block:: python from django import generic from viewform import LayoutMixin class SampleView(LayoutMixin, generic.ModelFormView): layout = Layout(...) **** Frontend ======== Frontend template assumes that your application contains a set of top level `modules` each one could restrict user access level and have own submenu. To quick start add `material.frontend` and `easy_pjax` into INSTALLED_APPS settings .. code-block:: python INSTALLED_APPS = ( 'material', 'material.frontend', 'easy_pjax' ... ) Add `material.frontend.context_processors.modules` into `context_processor` setting .. code-block:: python TEMPLATES = [ { ... 'OPTIONS': { 'context_processors': [ ... 'material.frontend.context_processors.modules', ], }, }, ] Add 'material.frontend.middleware.SmoothNavigationMiddleware' to `MIDDLEWARE_CLASSES` .. code-block:: python MIDDLEWARE_CLASSES = ( ... 'material.frontend.middleware.SmoothNavigationMiddleware', ... ) Add frontend urls into global urlconf module at urls.py .. code-block:: python from material.frontend import urls as frontend_urls urlpatterns = [ ... url(r'^admin/', include(admin.site.urls)), url(r'', include(frontend_urls)), ] To create a new module make a `modules.py` file, inside app directory, with following content .. code-block:: python from material.frontend import Module class Sample(Module): icon = 'mdi-image-compare' By default module expose a single view that renders html template from