Monday, October 28, 2013

Re: (3rd party app) How to safely reverse a custom user model admin url?

On 29/10/2013 8:15am, Ivan VenOsdel wrote:
> More simply, how do I put {{app_label}}_{{model_name}}_changelist in a
> template for a custom auth_user model without knowing the details of
> said model?
>
> I am guessing I don't want to refer to settings.auth_user_model in the
> template. It feels like the only way is to use the tag in that case and
> instead somehow call the changelist function (wherever that is) in the
> view. If so, anyone know how to do that?
>

You could either make a custom tag which behind the scenes can do (more
or less) anything or write a method or class for your view which returns
a dict or list or queryset.

I would decide which to use based on whether the result is mostly
display oriented or mostly business logic oriented. Business logic goes
in the view and display tweaks go in custom tags.

For a custom tag check
https://docs.djangoproject.com/en/1.5/howto/custom-template-tags/

The view code would be something like ...

from django.template import RequestContext
from django.shortcuts import render_to_response
from wherever import special_logic # returns list or queryset

def display_whatever(request, arg):
rqcontext = RequestContext(request)
content = { whatever: special_logic(arg), }
return render_to_response('whatever.html', content, rqcontext)

hth

Mike

--
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/526F3A30.4090607%40dewhirst.com.au.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment