Django Autocomplete light Forward fields outside Admin
MounikaAV opened this issue · 0 comments
MounikaAV commented
Hi, In my project I am using Django 2.1.15, Python 3.11, django-autocomplete-light==3.5.1.
`#views.py
class RefAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
date = self.forwarded.get('date', None)
opStart = int(self.forwarded.get('opStart', None))
opEnd = int(self.forwarded.get('opEnd', None))
qs = Pompe.objects.all()
.... Businuess logic
`#urls.py
path('refautocomplete_sopread/', views.RefAutocomplete_sopread.as_view(), name='refautocomplete_sopread' )
`#forms.py
prefix = 'reference-form'
date = forms.DateField(
initial=str(getTodaysTime().date()),
widget=forms.widgets.DateInput(format="%m/%d/%Y", attrs={'style': 'width : 100%', 'type': 'date', 'class':"form-date"}), label ='Début'
)
reference = autocompleteFormFunction.fieldAutoComplete(None, forms, Pompe, True,'refautocomplete_sopread', "pompe", None, "sopread-pumpSelect", forwardFieldName=('date', 'opStart', 'opEnd','user'))
user = forms.IntegerField(
widget=forms.HiddenInput(),
)
opStart = forms.IntegerField(
initial=1,
widget=forms.NumberInput(attrs={'type':"number",'class':"form-control", "placeholder":'Première opération', "width":"85%"}),
)
opEnd = forms.IntegerField(
initial=200,
widget= forms.NumberInput(attrs={'type':"number",'class':"form-control", "placeholder":'Dernière opération' }),
)
def __init__(self, user=None, *args, **kwargs):
super(SOPReadReferenceForm, self).__init__(*args, **kwargs)
if not(is_methodes(user) or is_atex(user)):
self.fields['date'].widget = forms.HiddenInput()
class Meta:
model = Pompe
fields = ('reference', 'date', 'opStart', 'opEnd','user')
`#frontview.py
formTable={}
formTable["formReference"] = SOPReadReferenceForm(initial={
'reference': request.GET.get('ref', ''),
'date': request.GET.get('date', str(getTodaysTime().date()) ),
'opStart': int(Profil_obj.opstart),
'opEnd': int(Profil_obj.opend),
'user': int(request.user.id),
}, user=request.user)
return render(request, 'sopread/sopread_start.html', {'formTable': formTable})
`#sopread_start.html
<form id="sopread-form" type="get" action="." style="margin: 0" onsubmit="sopReadVisualize();">
<div id="pageContent" class="content-section">
<div class="sopread-menu">
<fieldset class="form-group">
<legend class="border-bottom">
<div class="textCenter h2">
APP
</div>
</legend>
<div class="col-sm-3">
<strong>Référence :</strong>
</div>
<div class="col-sm-3">
{{ formTable.formReference.reference }}
</div>
<div class="col-sm-6">
{{ formTable.formReference.date }}
</div>
<br/><br/><br/>
<div class="col-sm-3">
<strong>Opérations :</strong>
</div>
<div class="col-sm-3">
{{ formTable.formReference.opStart }}
</div>
<div class="col-sm-3">
{{ formTable.formReference.opEnd }}
</div>
{{ formTable.formReference.user }}
<br/><br/><br/>
<button class="btn btn-outline-info btnSubmit" type="submit">
<strong>Visualiser</strong>
</button>
</fieldset>
</div>
</div>
</form>
In View.py Self.forwarded is getting None. Could anyone please help to understand why the values are not getting forwarded.
Thanks in Advance. !