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.

Source Distribution

django-initial-field-0.1.1.tar.gz (15.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page