Skip to main content

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

Project description

https://badge.fury.io/py/django-initial-field.svg https://travis-ci.org/PetrDlouhy/django-initial-field.svg?branch=master https://codecov.io/gh/PetrDlouhy/django-initial-field/branch/master/graph/badge.svg

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:

History

0.1.0 (2017-08-11)

  • First release on PyPI.

Project details


Download files

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

Files for django-initial-field, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size django-initial-field-0.1.1.tar.gz (15.3 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