A
A
arsenmusic2015-06-24 10:58:31
Django
arsenmusic, 2015-06-24 10:58:31

Passing data from multiple models to one view?

I meet Dzhanga, I train. Not strong in terminology, call if anything.
As a result, one (!) html page should turn out. Divided the data area is the only page on the model, painted the model. In the case when each model has its own view, everything is clear here. But what about in my case? Do I need to pass data from multiple models to one view? Or is it implemented differently? And one more thing, I have models with multiple entries, but there is one (stupidly a piece of text on the page), how can I specify this in the view (class based)? Because I already use ListView in it to display a list.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2015-06-24
@arsenmusic

class ListLinkView(ListView):
    model = FooterLink
    template_name = 'footer.html'

    def get_context_data(self, **kwargs):
        kwargs['another_object_list'] = AnotherModel.objects.all()
        kwargs['some_object_list'] = Some.objects.filter(some_variable__gt=5)
        return super().get_context_data(**kwargs)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question