I would like the link that a user clicks on to instantiate a model differently on a subsequent view.
I have a page ‘tools.html’ that is a templateView:
Urls.py
path(
"tools/",
TemplateView.as_view(template_name="pages/tools.html"),
name="tools",
)
tools.html has two links (AP and AD) on it - both should go to the same template ’se_balance.html’ a page where users complete a form.
The view for se_balance.html is:
class CaseView(TemplateView):
model = Case
template_name = "../templates/se_balance.html"
def get(self, *args, **kwargs):
print('getting')
case_form = CaseForm
sideeffect_formset = SideeffectFormSet(queryset=SideEffect.objects.none())
return self.render_to_response(
{ "case_form": case_form,
"sideeffect_formset": sideeffect_formset,
"sideeffect_formsethelper": SideEffectFormSetSetHelper,
}
)
The ‘Case ‘ model is as follows:
class Case(TimeStampedModel):
# get a unique id for each patient - could perhaps use this as slug if needed
case_id = models.UUIDField(
primary_key=True, unique=True, default=uuid.uuid4, editable=False
)
# Remove blank=True if we want to make login compulsory
user = models.ForeignKey(
settings.AUTH_USER_MODEL, blank=True, null=True, on_delete=models.SET_NULL
)
P_CHOICES = [(‘AD’, ‘AD’),
(‘AP’, ‘AP’),]
Depending on the link that was clicked at tools.html I would like the model instantiated differently (i.e.e with P_CHOICEs as Either ‘AD’ or ‘AP’ but I am not sure of the correct way to do this?
Thanks!