19๐
โ
You can use HiddenInput
as ref1
widget:
class TestModelForm(ModelForm):
class Meta:
model = TestModel
widgets = {
'ref1': forms.HiddenInput(),
}
Another option is saving form with commit
argument equal False
. This way you can include only visible fields in form and then update model instance with needed data:
def some_view(request):
# ...
if request.method == 'POST':
form = TestModelForm(request.POST)
if form.is_valid():
instance = form.save(commit=False)
ref = get_ref_according_to_url()
instance.ref1 = ref
instance.save()
# ...
๐คndpu
0๐
NOTE: I am using (Django 3.2)
I tried to add a widget and it did not work for me, but I solved it in a simpler way without using widgets.
class TestModelForm(ModelForm):
ref1 = forms.CharField (widget = forms.Textarea(
attrs = {
'hidden': '',
}
))
I hope this helps you or others ๐
๐คYousif Al-Zoubi
- Python ctypes MemoryError in fcgi process from PIL library
- Django โ links generated with {% url %} โ how to make them secure?
Source:stackexchange.com