﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31671	Unable to get PK or ID for One-to-One field within template	FlavienJP	nobody	"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"	Bug	closed	Template system	3.0	Normal	invalid	url, one-to-one field		Unreviewed	0	0	0	0	0	0
