django-fancy-feast

Additional form fields for Django.


License
BSD-3-Clause
Install
pip install django-fancy-feast==0.2

Documentation

Django Fancy Feast

Django Fancy Feast is a collection of handy things for Django.

Quick Start

Run pip install django-fancy-feast

Add 'fancy_feast' to your INSTALLED_APPS setting:

INSTALLED_APPS = [
    ...

    'fancy_feast',
]

Examples

DataModelChoiceField: An HTML select field where the options have data- attributes that are based on model fields.:

# models.py
class Color(models.Model):
    name = models.CharField(max_length=254)
    value = models.CharField(max_length=254)
    opacity = models.DecimalField()

    def __str__(self):
        return self.name
# forms.py
from fancy_feast.forms.fields import DataModelChoiceField

class ExampleForm(forms.Form):
    icon_color = DataModelChoiceField(queryset=Color.objects.all(),
                                      data_attributes={'color':'value',
                                                       'opacity': 'opacity'})

The result would be a select field like this:

<select id="id_icon_color" name="icon_color">
    <option value="" selected="selected">---------</option>
    <option data-color="#53DF83" data-opacity="0.5" value="1">Happy Green</option>
    <option data-color="#47D2E9" data-opacity="0.9" value="2">Flyby</option>
    <option data-color="#EEEEEE" data-opacity="1.0" value="3">Concrete</option>
    <option data-color="#3F3F3F" data-opacity="0.1" value="4">The Dark Side</option>
</select>