Задать вопрос

Тел: +7 965 3737 888

440

Просмотров

1

Ответов

Generic object_detail view with multiple named URL filters

<p>This snippet is greatly inspired by <a href="http://djangosnippets.org/users/jlorich/">@jlorich</a>'s useful <a href="http://djangosnippets.org/snippets/2436/">#2436</a>.</p>
<p>The main difference is that I wanted to choose the names of my URL params instead of being forced into naming them "value1", "value2", etc. When reversing the URL you have to remember that the kwargs aren't friendly. By using the same names in the filters list, you don't have to change the way your otherwise write the URL pattern. Also it's clear throughout how you'll be filtering the QuerySet.</p>
<p>The other change I made was "erroring early". This avoids running the QuerySet all over again inside object_detail() just to have it raise an exception we could have caught the first time.</p>

Вопрос полезен? Да0/Нет0
file_4004.py(1.8Кб)
None

Ответы (1):

Ответbluerat:20.02.2012
Ответ полезен? Да0/Нет0

Thanks, very useful :-)