Skip to content

yoowillns/django-materialize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

===== Materialize for Django

Materialize is a simple implementation of materializecss for Django.

More information on materializecss

http://materializecss.com/

Requirements

  • Python >= 2.7
  • Django >= 1.8

Table of Contents


Quick start

Download ZIP or clone this repository (https://github.com/yoowillns/django-materialize)

Install

  1. Install:

    setup.py install

  2. Add "materialize" to your INSTALLED_APPS settings :

    INSTALLED_APPS = [
        ...
        'materialize',
    ]
  3. In your templates, load the materialize library and use the {% load materialize %}

Project Structure

Create templates folder in project: /templates/layout/MainLayout.html

Template Main Layout

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Materialize Demo</title>
    <!-- Include static files in project -->
    {% include 'lib/materialize_static.html' %}
</head>
<body>
    <div class="container">
        {% block content %}
        <!-- Content project -->
        {% endblock %}
    </div>
</body>
</html>

Template Content

{% extends 'layouts/MainLayout.html' %}

{% load materialize %}

{% block content %}
    <div class="row">
        <div class="col s6">
            <form class="col s12" action="" method="post">
                {% csrf_token %}

                {% materialize_form form %}

                <button class="btn waves-effect waves-light" type="submit" name="action">Register
                </button>
            </form>
        </div>
    </div>
{% endblock %}

Examples

Model Example

from django.db import models

class Product(models.Model):
  name = models.CharField(max_length=10, verbose_name='Nombre', null=False)
  category = models.ManyToManyField(Category, verbose_name='Categoria')
  count = models.IntegerField(verbose_name='Cantidad')
  date_buy = models.DateField(verbose_name='Fecha de Compra')
  image = models.FileField(upload_to='uploads', verbose_name='Imagen')
  description = models.TextField(verbose_name='Descripcion')
  state = models.BooleanField(verbose_name='Estado', default=False)
  date = models.DateTimeField(auto_now_add=True)

  def __str__(self):
      return self.name

  class Meta:
      verbose_name = 'Producto'
      verbose_name_plural = 'Productos'

Model Form Example

from django import forms
from django.forms import ModelForm
from models import *

class ProductForm(forms.ModelForm):
  class Meta:
      model = Product
      fields = '__all__'

Template Form Example

{% extends 'layouts/MainLayout.html' %}

{% load materialize %}

{% block content %}
    <div class="row">
        <div class="col s6">
            <form class="col s12" action="" method="post" enctype="multipart/form-data">
                {% csrf_token %}

                {% materialize_form form form_title='Producto' data_success='Correcto' %}
                
                <button class="btn waves-effect waves-light" type="submit" name="action">Register
                </button>
            </form>
        </div>
    </div>
{% endblock %}

Result Form

alt text

Extra

Customize Label Erros

Use class .label-error in css style in project

About

Materialize forms for django

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published