This code in the chemical model indicates that I'm trying to display two different views of the same chemical which has certain data in a details 1:1 record

class Chemical(models.Model):
    ...
    def get_absolute_url(self):
        detail = self.get_detail()
        if detail and detail.report_type == INTRO:
           return f"/report/intro/{self.id}/"
        return f"/report/audit/{self.id}/"




But it doesn't matter what report_type is selected, the same report displays. Print statements inserted indicate the correct report_type branch is being executed and the correct url is being returned.

The url which displays the report is always the first of whichever of the following patterns is above the other ...



from django.urls import re_path
from report import views as report_views

app_name = "report"

urlpatterns = [
    re_path(r"(?P<pk>\d+)/$",
        report_views.audit,
        name="audit",
    ),
    re_path(r"(?P<pk>\d+)/$",
        report_views.intro,
        name="intro",
    ),
]




Both reports are identifiably different. In the above configuration the audit report always shows no matter which report_type is selected.

Where am I going wrong?

I have tried to get reverse() working by following along with ...

https://docs.djangoproject.com/en/2.2/ref/models/instances/#get-absolute-url

... but to no avail. I think if I can get it working with specified urls I should be able to get reverse working.

Thanks for any hints

Cheers

Mike

--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4d503dfa-5804-9e2b-a0f7-c65ef8f81847%40dewhirst.com.au.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to