You can use Form.initial
, which is explained here.
You have two options either populate the value when calling form constructor:
form = JournalForm(initial={'tank': 123})
or set the value in the form definition:
tank = forms.IntegerField(widget=forms.HiddenInput(), initial=123)
More Related Contents:
- How to change the file name of an uploaded file in Django?
- Customize/remove Django select box blank option
- Django – form.save() is not creating ModelForm
- Django ModelForm to have a hidden input
- django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. plz help me out plz
- What is the difference between null=True and blank=True in Django?
- What’s the difference between select_related and prefetch_related in Django ORM?
- dynamically add field to a form
- Can “list_display” in a Django ModelAdmin display attributes of ForeignKey fields?
- Django – No such table: main.auth_user__old
- Django reverse lookup of foreign keys
- Multiple Models in a single django ModelForm?
- How to create an object for a Django model with a many to many field?
- django abstract models versus regular inheritance
- Django Unique Together (with foreign keys)
- Getting TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries
- Django : Table doesn’t exist
- Django Rest Framework and JSONField
- How to filter objects for count annotation in Django?
- How do I separate my models out in django?
- Change Django ModelChoiceField to show users’ full names rather than usernames
- Using request.user with Django ModelForm
- Writing a __init__ function to be used in django model
- Difference between AbstractUser and AbstractBaseUser in Django?
- Duplicating model instances and their related objects in Django / Algorithm for recusrively duplicating an object
- Override a form in Django admin
- How can I set two primary key fields for my models in Django?
- CSRF Token missing or incorrect
- Django get_profile() method not working on extended User model
- How to delete a record in Django models?