Hi,
I have a record to save in the app database.
so I have created a table in models.py SurveillanceDesPuits
as:
class SurveillanceDesPuits(models.Model):
PUITS = models.ForeignKey(Surveill_Wells ,to_field='WellID', on_delete=models.CASCADE)
DATE_TEST= models.DateField()
MODE = models.CharField(max_length=6)
......
.....
post_date = models.DateTimeField(auto_now_add=True)
author = models.CharField(max_length=15, default= User)
def __str__(self):
return self.PUITS.WellID
def get_absolute_url(self):
return reverse('WellMonitor')
and my formes.py is :
class SurveillanceDesPuits_F(forms.ModelForm):
PUITS = forms.ModelChoiceField(required=False,label='Well ID', queryset=Surveill_Wells.objects.all())
DATE_TEST = forms.DateField(label='Control Date',widget=forms.DateInput(attrs={"class":"form-control", 'type':'date'}))
MODE = forms.CharField(label='Mode',max_length=6)
....
.....
class Meta:
model= SurveillanceDesPuits
fields=('PUITS','DATE_TEST','MODE','CS','SITUATION','DUSE','PRES_TBG','PRES_CSG','PRES_AVD','RESEAU_GL','ANNULAIRE_TECH','OBSERVATION','Controle_Pression_ENSP','Test_Puits','Controle_Pression_DP')
So I have a view and the result is good.
and the record input page is like this:
what I need to do is auto-fill for example when I chose a well from the list
it fills the rest of the fields from the last record of the same well!
so is that possible or easy to do? and how to do it?