Can I use the values from a form in other form with Django?
I have a Django app with two forms where the views.py looks like this:
import pandas as pd
import numpy as np
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.template.response import TemplateResponse
from pbmcalculator.models import PbmCalculator, simulator
from django.core.cache import cache
import json
@login_required
def subs_calc(request):
# this is from the first form #
selection = request.GET.get("id", None)
customer = request.GET.get("customer", None)
initial_date = request.GET.get("initial_date", None)
final_date = request.GET.get("final_date", None)
if selection is not None and 'initial_date' in request.GET:
calculation_target = PbmCalculator(customer, initial_date, final_date)
html = TemplateResponse(
request,
"pbmcalculator/table.html",
{
some operations
},
)
return html
if 'generico_sim' in request.GET:
# this is from the second form #
brand_sim = request.GET.get("brand_sim",None)
generico_sim = request.GET.get("generico_sim",None)
marca_sim = request.GET.get("marca_sim",None)
initial_date_sim = '2021-08-08'
final_date_sim = '2021-08-15'
calculation_sim = simulator(brand_sim, initial_date_sim, final_date_sim)
html = TemplateResponse(
request,
"pbmcalculator/table1.html",
{
some operations
},
)
return html
return render(request, "pbmcalculator/subs_calc.html", {"selected": False})
So I want to use the variables initial_date and final_date in the second if statement to fill the initial_date_sim and final_date_sim. I tried several ways but none worked. Some idea?
I solved this issue by taking the values through the ajax of each form, there it doesn't matter if the value comes from one or the other. then the second form will be filtered by the dates of the first as I wanted. Thank you Jelle for your time.