Giter VIP home page Giter VIP logo

django-gradient-colorfield's Introduction

django-gradient-colorfield

This module fills the need of having a colorfield that's usable in both django models and forms.

Makes use of lgcolor.

Installation

  • Add gradient_colorfield folder to project root
  • Add gradient_colorfield to your INSTALLED_APPS
  • Collect static files with ./manage.py collectstatic

Usage

In your models, you can use it like this:

from django.db import models

from gradient_colorfield.fields import GradientColorField


class AppModel(models.Model):
   header_background = GradientColorField(verbose_name=u'Header Background',
                                          default='linear-gradient(to bottom, #00f260 0%, #0575e6 100%)'
                                          )
   footer_background = GradientColorField(verbose_name=u'Footer Background',
                                          default='linear-gradient(to bottom, #00f260 0%, #0575e6 100%)'
                                          )

   def __str__(self):
       return 'Gradient{}'.format(self.id)

In your ModelForm, you can use it like this:

from django import forms
from app.models import AppModel

class AppForm(forms.ModelForm):
   class Meta:
       model = AppModel
       fields = ['header_background', 'footer_background']

In your FormWidget, you can use it like this:

from django import forms

from gradient_colorfield.fields import GradientColorWidget

class AppForm(forms.Form):
    header_background = forms.CharField(label='Header Background', max_length=20, widget=GradientColorWidget(),
                                        initial='linear-gradient(to bottom, #00f260 0%, #0575e6 100%)',
                                       )
    footer_background = forms.CharField(label='Footer Background', max_length=20, widget=GradientColorWidget(),
                                       initial='linear-gradient(to bottom, #00f260 0%, #0575e6 100%)')

In your Template, you can use it like this:

{{form.media}}

{% for field in form %}
    {{field}}
{% endfor %}

Run Sample App

  • Create virtualenv virtualenv -p $(which python3.6) env3 -- Python 3.6
  • Activate virtualenv source env3/bin/activate
  • Install Dependencypip install -r requirements.txt
  • Migrate cd sample-app && python manage.py migrate
  • Run Django Sample-app python manage.py runserver

django-gradient-colorfield's People

Contributors

vivekparat avatar vkmrishad avatar

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.