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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-initial-field-0.1.1.tar.gz
.
File metadata
- Download URL: django-initial-field-0.1.1.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79a31850b4733317ac294895cf17cd2ee3791bb87d1978faadcb1af58101faea |
|
MD5 | 177e1496a69055cb426483d77b256698 |
|
BLAKE2b-256 | ca5ce146cba2218623c8bec7173fc464e4199b686076bb8ffda3b4443441a566 |