Opened 4 years ago
Closed 4 years ago
#31671 closed Bug (invalid)
Unable to get PK or ID for One-to-One field within template
Reported by: | FlavienJP | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 3.0 |
Severity: | Normal | Keywords: | url, one-to-one field |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Hello,
I'm trying to render a Truck page and to add a link to the Router associated view.
Router and Truck are linked together through the Order model.
The link between Order and Router is made with a one-to-one field as decribed below :
class Router(models.Model): order = models.OneToOneField('organisation.Order', on_delete=models.PROTECT)
And in my ordering template i'm generating the link to the Router view from the Truck view :
{% for order in truck.order_set.all %} <td><a href="{% url 'operation:router_view' pk=order.router.id %}">{{ order.router }}</a></td> {% endfor %}
Then i get the following error :
NoReverseMatch at /organisation/truck/1 Reverse for 'router_view' with keyword arguments '{'pk': ''}' not found. 1 pattern(s) tried: ['operation/router/(?P<pk>[0-9]+)$']
PK remains empty but if only request for 'order.router.id' out of {% url %}, i'm able to get the pk (or id).
{% for order in truck.order_set.all %} <td>{{ order.router.id}}</td> {% endfor %}
And also through the python console :
>>>Truck.objects.get(pk=1).order_set.all()[0].router.pk 1
There is something strange within {% url %} section.
Thanks for your help.
Flavien
Change History (2)
comment:1 by , 4 years ago
Description: | modified (diff) |
---|
comment:2 by , 4 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Bad idea to work late ... I've forget that two orders from # types was attached to this Truck.
Sorry.