Saturday, November 9, 2013

Re: List in a Template

SOLVED (sort of).

On Sat, Nov 9, 2013 at 2:56 PM, donarb <donarb@nwlink.com> wrote:

> If the user is a manager, you should be able to just test for membership in
> the list:
>
> {% if user in mgr_list %}

This made perfect sense after I realized that I was looking at a list
of objects and not just the email string returned from the model. But,
it didn't work.

> Another option would be to have a property such as "is_manager' and test for
> that in the template.
>

I thought about this but I also need to see if the manager status has
expired. So I solved it in this way, though it may not be the most
efficient.

The view now creates an actual list of email addresses of users with
active manager status.

class IndexView(TemplateView):

template_name = 'index.html'

def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
mlist = []
for x in Manager.objects.all():
if x.expires >= now():
print(x.expires)
mlist.append(x.user.email)
context['mgr_list'] = mlist
return context


Is there a better way? Will this be particularly slow if I have 1,000 managers?

Thanks,
Tim

--
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%2B%3DOU3Vg7jizGkkLmh-pkxv6mRZsFQxJofive-gKjrzKZMFiYA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate