Hi Victor,

I think this is a very good question.  I've been considering what the best
approach would be and decided on either using a decorator as you've
mentioned or implementing class based views.  You can create base view
classes that load common data for the different types of pages.  You would
then have specific views subclass one of the base view classes to inherit
the loading of the common data while acting on data specific to their view.

I'm curious if anyone else has any opinions or experiences loading common
page elements in a clean and DRY manner.

--
Alex

On Thu, Sep 29, 2011 at 5:59 PM, Victor Hooi <victorh...@gmail.com> wrote:

> Hi,
>
> We have a common navigation bar on nearly every page (view) that contains a
> dropdown - this dropdown is populated with items from a database table. This
> dropdown also has AJAX behaviour attached to it.
>
> I'm thinking I can create a decorator that will retrieve the list from the
> database, and return a Python list
>
> We can then wrap every single view in this decorator, and then pass the
> list to the template for rendering.
>
> Firstly - is there a more elegant alternative, rather than wrapping every
> single view in this decorator? (Middleware? Or is that a poor fit here?
> Anything else?).
>
> And secondly - are there are any performance issues here? We're making
> database calls with every single view, just to get a list for a navigation
> dropdown. Smarter way?
>
> I know I can use the caching middleware to cache entire pages, or even
> template fragments - but how about caching a single list() like this? What
> are other methods people are using to tackle this?
>
> Cheers,
> Victor
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/8cKewo2DudcJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to