Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django Autocomplete light Forward fields outside Admin #1345

Open
MounikaAV opened this issue Nov 8, 2023 · 0 comments
Open

Django Autocomplete light Forward fields outside Admin #1345

MounikaAV opened this issue Nov 8, 2023 · 0 comments

Comments

@MounikaAV
Copy link

MounikaAV commented Nov 8, 2023

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. !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant