24๐
โ
I suggest you remove your object_list
view,
define a dictionary for this specific view,
all_models_dict = {
"template_name": "contacts/index.html",
"queryset": Individual.objects.all(),
"extra_context" : {"role_list" : Role.objects.all(),
"venue_list": Venue.objects.all(),
#and so on for all the desired models...
}
}
and then in your urls:
#add this import to the top
from django.views.generic import list_detail
(r'^$', list_detail.object_list, all_models_dict),
๐คthikonom
70๐
I ended up modifying @thikonom โs answer to use class-based views:
class IndexView(ListView):
context_object_name = 'home_list'
template_name = 'contacts/index.html'
queryset = Individual.objects.all()
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context['roles'] = Role.objects.all()
context['venue_list'] = Venue.objects.all()
context['festival_list'] = Festival.objects.all()
# And so on for more models
return context
and in my urls.py
url(r'^$',
IndexView.as_view(),
name="home_list"
),
- [Django]-How do you configure Django to send mail through Postfix?
- [Django]-Django model method โ create_or_update
- [Django]-No module named urllib.parse (How should I install it?)
9๐
If you want to build it on Django 1.5 you will be able to utilize stable version of CBVs. Please find code below.
Great doc you can find here https://docs.djangoproject.com/en/dev/topics/class-based-views/mixins/
class ProductsCategoryList(ListView):
context_object_name = 'products_list'
template_name = 'gallery/index_newborn.html'
def get_queryset(self):
self.category = get_object_or_404(Category, name=self.args[0])
return Products.objects.filter(category=self.category)
def get_context_data(self, **kwargs):
kwargs['category'] = Category.objects.all()
# And so on for more models
return super(ProductsCategoryList, self).get_context_data(**kwargs)
๐คgrillazz
- [Django]-Overriding the save method in Django ModelForm
- [Django]-Whats the simplest and safest method to generate a API KEY and SECRET in Python
- [Django]-CSRF validation does not work on Django using HTTPS
Source:stackexchange.com