django-initial-field

Sometimes it is needed to pass some default values to the objects created by ModelForm. This simple mixin enables that by creating HiddenInput fields and passing initial parameters to the created Model


Keywords
django-initial-field
License
MIT
Install
pip install django-initial-field==0.1.1

Documentation

Django initial form field

https://travis-ci.org/PetrDlouhy/django-initial-field.svg?branch=master

Sometimes it is needed to pass some default values to the objects created by ModelForm. This simple mixin enables that by creating HiddenInput fields and passing initial parameters to the created Model

Documentation

The full documentation is at https://django-initial-field.readthedocs.io.

Quickstart

Install Django initial form field:

pip install django-initial-field

Use InitialFieldMixin in your ModelForm and set initial_field parameter:

class MyForm(InitialFieldsMixin, forms.ModelForm):
    initial_fields = ('my_field')

Then set initial value in your FormView:

class MyView(FormView):
         def get_initial(self):
                  return {'my_field': "some value"}

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package: