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 details)

Uploaded Source

File details

Details for the file django-initial-field-0.1.1.tar.gz.

File metadata

File hashes

Hashes for django-initial-field-0.1.1.tar.gz
Algorithm Hash digest
SHA256 79a31850b4733317ac294895cf17cd2ee3791bb87d1978faadcb1af58101faea
MD5 177e1496a69055cb426483d77b256698
BLAKE2b-256 ca5ce146cba2218623c8bec7173fc464e4199b686076bb8ffda3b4443441a566

See more details on using hashes here.

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