python - Django - display several model queries either a template or nested templates -


i new django , have learned display model data in template (using django.generic listview in views) putting in table using like:

{% each in model_list %}  <td>{{each.attribute}}</td> {% endfor %} 

what should if want perform several queries on same model(data) , present each of returned dictionaries in different part of template view (imagine if had 1,000 baseball players , wanted display them in separate tables on same page corrosponding team)?

my thought should use django documentation: https://docs.djangoproject.com/en/1.4/topics/class-based-views/

class publisherbooklistview(listview):  context_object_name = "book_list" template_name = "books/books_by_publisher.html"  def get_queryset(self):     self.publisher = get_object_or_404(publisher, name__iexact=self.args[0])     return book.objects.filter(publisher=self.publisher)  def get_context_data(self, **kwargs):     # call base implementation first context     context = super(publisherbooklistview, self).get_context_data(**kwargs)     # add in publisher     context['publisher'] = self.publisher     return context 

however, using listview seems can pass 1 dictionary template @ time - documentation link above shows how url patterns, hoping have more 1 result on same page (i.e. player stats yankees , red soxx together, not url pattern show yankees on 1 iteration of template , red soxx on another)

--i feel there's massive hole in django understanding here... because seems should simple: - maybe through parent/child templates? how url pattern used in 'query' work?

another source found on filters - seems straightforward , promising: http://www.pfinn.net/custom-django-filter-tutorial.html

anyway, i'd appreciate can point me in right direction typically done in situations this.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -