Hello,
I have a problem because I don't know how could I send one specific parameter. I've sent other parameters sometimes in others apps but this time is more difficult.
Below it's my code. I want to send 'p', which is an object. The problem is that I can't send it in else because I've defined p outside (if). So when I tried to send it, p is not defined. I can't define it outside because I need id_medioedit, which is an id obtained from template in medioedit_id form.
Anyone who knows how to solve this?
Thank you in advance
Views.py
if 'medioedit_id' in request.POST:
formularioeditarmedios = EditMediosForm(request.POST)
try:
id_medioedit = request.POST['medioedit_id']
p = Medios.objects.get(pk=id_medioedit)
mensaje = {"status":"True","medioedit_id":p.id}
if formularioeditarmedios.is_valid():
...
else:
formularioeditarmedios = EditMediosForm(p=p)
Forms.py
class EditMediosForm(forms.Form):
#initial='somevalue'
titulo = forms.CharField(max_length=140, widget=forms.TextInput(attrs={'style': 'width:140px'}))
def __init__(self,p,*args,**kwargs):
p = kwargs.pop("p", None)
super(EditMediosForm, self).__init__(*args,**kwargs)
self.fields['titulo'].initial = p.titulo