I have the following django app structure:
models.py
class CodiceCommessa(models.Model):
codice_commessa=models.ForeignKey(Informazioni_Generali, on_delete=models.CASCADE, null=True)
class Informazioni_Generali(models.Model):
codice_commessa= models.CharField('Codice', unique=True, max_length=5)
data_registrazione=models.DateField()
forms.py
class CodiceCommessaForm(forms.ModelForm):
class Meta:
model = CodiceCommessa
fields = "__all__"
views.py
def altri_costi_commessa(request):
cod=[]
if request.method == 'POST':
year = request.POST['year']
if request.method == 'POST':
form = CodiceCommessaForm(request.POST)
if form.is_valid():
cod = form.save()
else :
form = CodiceCommessaForm()
In my template I have set the form. All works, but I want that, when I select a year, automatically django show me only the codice_commessa
that match the year in the field data_registrazione
.
Is it possibile to get it?