I have a path that looks like so :
http://127.0.0.1:8000/lineitems/line_forecast/add/33
33 is the parent id for which I want to create a child element
When using the link, it goes to a view function that should render a form with the required fields, one of them being the parent id (33) which ideally would be a hidden field. By default, I get a select list with all parents which is not the desired effect.
Beside, when I want to update a given forecast, using path http://127.0.0.1:8000/lineitems/line_forecast/update/55, the form populates but I get a select option list of all the parents. I obviously don’t want that, if fact that parent field should be hidden as parent cannot be changed.
Some light with this would be appreciated, understanding it is two problems in one.
def add_line_forecast(request, pk):
if request.method == "POST":
form = LineForecastForm(request.POST)
if form.is_valid():
form = form.save(commit=False)
# form.owner = request.user
form.save()
return redirect("line-items")
else:
import pprint
pprint.pprint(pk)
form = LineForecastForm()
return render(request, "lineitems/line_forecast_form.html", {"form": form})
As depicted above, what I was thinking is that by getting the pk from the path link and then pass it along when the else clause kicks in would be straightforward, but that does not seem to be the case. Some how I need to eliminate the select html tag and make it hidden. I am rather confused with something that I think sohuld be trivial.