Monday, July 27, 2015

Re: URL Generation

> I think what you want is something like:
>
> # team URL's
> url(
>     regex=r'organization/(?P<organization_pk>\d+)/team/',
>     view=include('project.teams.urls', namespace='organization-team',
> app_name='team'),
> ),
>
> # competition team listing - project.competitions.urls
> url(
>     regex=r'^(?P<competition_pk>\d+)/team/',
>     view=include('project.teams.urls', namespace='competition-team',
> app_name='team'),
> ),


I also believe this is correct.


>
> Did you follow the example at
> https://docs.djangoproject.com/en/1.8/topics/http/urls/#id4?
>

I had circled back around to that page several times in the past and couldn't grasp the concept of how the internals made the determination of which instance namespace to use. Then, given your answer above, I re-read it again and saw this:

"""
Using this setup, the following lookups are possible:

If one of the instances is current - say, if we were rendering the detail page in the instance 'author-polls' - 'polls:index' will resolve to the index page of the 'author-polls' instance; i.e. both of the following will result in "/author-polls/".
"""

*facepalm*

That's exactly the behavior I need. I think this is one of those cases where I zoomed in on an issue a little too far (been working on this for several months on/off for a personal project).

However, I still think I'll need to change my URL structure up a bit. Assuming I implement as stated above, I'll then have two different signatures for the same namespace ({% url 'team:detail' org_pk %} and {% url 'team:detail' org_pk comp_pk %}), which I think was part of the problem as to why I couldn't grasp the application namespace. It also means I would need to determine the signature I need to use ahead of time , which makes this question moot since I can add other logic to generate the correct URL. I have a custom row-level permission system and heavy view/model inheritance in play as well (a majority of my CBV's are literally a single line to specify the permission needed), and I was using that to pull in information needed for permission checks from the URL kwargs before wasting time rendering, but I believe I can pull in the necessary bits from a simplified URL structure with a little bit of extra effort spent inspecting the primary object in question.

Thank you for the enlightenment. I think this is my first question post, but watching threads to/from others has definitely helped immensely on other topics. 

-James

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUchqRnQT3S67bke5LesKCTp%2BKsUNiF%2Baq9j4GaggePiw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment