# I use mixins in a project where i need to show a list of Collection
objects in both list and detail views,
# maybe this method would help you if you are using generic class-based
views?

class CollectionSidebarMixin(object):
    # Add collections to the context
    def get_context_data(self, **kwargs):
        context = super(CollectionSidebarMixin,
self).get_context_data(**kwargs)
        context['collections'] = Collection.objects.all()
        return context

# and you can use the mixin for list and detail views:
class CollectionList(CollectionSidebarMixin, ListView):
    model = Collection
    context_object_name = 'collections'

class CollectionDetail(CollectionSidebarMixin, DetailView):
    model = Collection
    context_object_name = 'current_collection'


On Tue, Feb 5, 2013 at 2:12 PM, Jonas Geiregat <jo...@geiregat.org> wrote:

> On Tue, Feb 05, 2013 at 02:06:28AM -0800, Stefano Tranquillini wrote:
> > Now, i can create a base.html template where i render the data. but, how
> > should i do the population of these lists?
> > Should i create a middleware that for each request populates the lists?
> > or what?
> I think that a Context Processor will be a better option.
>
> --
> 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+unsubscr...@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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


-- 
*E. Serkan Sökmen*
Django / Front-end Developer @Teknolab <http://teknolab.org/>
Personal works: serkansokmen.com <http://www.serkansokmen.com>

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to