Skip to main content

Django model field list field

Project description

Django model field list field

Build Status GitHub release PyPI release Python version GitHub issues Code quality Coverage GitHub license

This is a Django model field that provides a list of some other model's fields. Fields can be multi-selected and "under the hood" are stored as a comma-separated string. Also package provides simple form field with the same capabilities.

Requirements

  • Python 2.7+ or Python 3.3+
  • Django 1.11+

Installation

Install django-mflf using pip:

pip install django-mflf

Add model_field_list to INSTALLED_APPS. Example:

INSTALLED_APPS = (
    ...
    'model_field_list',
    ...
)

Example usage

Model field:

from model_field_list import ModelFieldListField

class ProductKind(models.Model):
    name = models.CharField(max_length=100)
    comparison = ModelFieldListField('comparison criteria', source_model=Product)

If referenced model has many fields it would be useful to use FilteredSelectMultiple in Django admin:

from django.contrib.admin.widgets import FilteredSelectMultiple

class ProductKindAdminForm(forms.ModelForm):
    class Meta:
        widgets = {
            # different widget label is intentional
            'comparison': FilteredSelectMultiple('product properties', False)
        }

Simple form field:

from django.contrib.admin.widgets import FilteredSelectMultiple
from model_field_list import ModelFieldListFormField

class ProductExportForm(ExportForm):
    export_fields = ModelFieldListFormField(source_model=Product, label='Export fields',
                                            widget=FilteredSelectMultiple('свойства товара', False))

Limitations

  • All model fields are listed, no option to filter them in any way.
  • Field order can't be customized - they are sorted by the order of their definition in a model.

Project details


Release history Release notifications

This version

0.0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-mflf, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size django_mflf-0.0.1-py2.py3-none-any.whl (9.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size django-mflf-0.0.1.tar.gz (6.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page