This is actually quite simple (conditional field settings) - here's a quick example:
from django.forms import Modelform from django.forms.widgets import HiddenInput class SomeForm(ModelForm): def __init__(self, *args, **kwargs):
So, the key points from this:
self.instance represents a related object if the form is connected. I believe that it is passed as a named argument, so in kwargs , which the parent constructor uses to create self.instance .- You can change the properties of a field after calling the parent constructor.
- Widgets are ways to display forms. HiddenInput basically means
<input type="hidden" .../> .
There is one limitation; I can interfere with the input to change the value if I change the POST / GET data. If you do not want this to happen, something that needs to be considered overrides the form validation method (clean ()). Remember that everything in Django is just objects, which means that you can actually modify the objects of the class and add data to them at random (this will not be saved). So in __init__ you could:
self.instance.olddrivers = instance.drivers.all()
Then in your pure method for the specified form:
def clean(self):
user257111
source share