django-custom-pyforms-forms

The library implements the functionality to add dynamic extra fields to the Pyforms Web applications.


License
MIT
Install
pip install django-custom-pyforms-forms==0.1

Documentation

Pyforms custom forms

The library implements the functionality to add dynamic extra fields to the Pyforms Web applications.

 

Usage

For this explanation we are going to use the next pyforms application as example. This application is used to manage the django Expense model.

from reimbursements.models import Expense
from pyforms_web.widgets.django import ModelFormWidget

class ExpenseForm(ModelFormWidget):

    MODEL = Expense
    
    FIELDSETS = [
        ('document_number', "requisition_number", 'is_social'),
        ' ',
        ('_costcenter', '_financeprj', 'expensecode'),
        ('eur_value', "value", "value_currency"),
        ' ',
        ('receipt_date', ' ', ' '),
        'receipt',
        ' ',
        'description'
    ]

To add extra custom fields to this application we should inherit it from CustomModelForm. This class adds 2 fields, the select_form for the user to select the extra fields, and the customized_form used to render the extra fields.

...
from model_extra_fields.widgets.custom_model_form import CustomModelForm

class ExpenseForm(CustomModelForm):
    ...
    
    FIELDSETS = [
        ...
        'select_form',
        'customized_form',
        ...
    ]

Forms configuration

The next steps demonstrates how to configure extra custom fields.

First select the application Custom forms on the user menu.

Menu

Create the forms you need and associate them to a Content Type.
These forms will be available when editing an object from the selected content type.

Add custom form

The Formset field configures the organization of the configured extra fields, ala Pyforms.

Edit the custom form

To each custom form you can associate several fields from diferent types.
These fields can be customized as it is show in the image bellow.

Edit a field

Result

First ExpenseForm app inherit from the ModelFormWidget class.

ModelFormWidget

Second ExpenseForm app inherit from the CustomModelForm class. On this app it is possible to visualise the [Extra information] control which allow the user to select the form with the extra fields he wiches to complete.

CustomModelForm

 

Install & configure

Clone the repository

> git clone git@github.com:fchampalimaud/pyforms-custom-forms.git

Install the library

> pip install ./pyforms-custom-form

Add the app to the django settings.py

INSTALLED_APPS = [
    ...
    'model_extra_fields',
    ...
]

Execute the django migrations

> python manage.py migrate model_extra_fields