from news models import News from django views generic list_detail imp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from news.models import News
from django.views.generic.list_detail import object_list, object_detail
from django.views.generic.create_update import update_object
def main_page(request):
kwargs = {}
kwargs['queryset'] = News.objects.filter(active=1).order_by('-id')
kwargs['template_name'] = 'news.html'
kwargs['paginate_by'] = 5
return object_list(request,**kwargs)
def news_wrapper(request,category,page=1):
kwargs = {}
kwargs['queryset'] = News.objects.filter(category__name=category).filter(active=1).order_by('-id')
kwargs['template_name'] = 'news.html'
kwargs['paginate_by'] = 1
kwargs['page'] = page
kwargs['extra_context'] = {'category':category}
return object_list(request,**kwargs)
def edit_news(request,id):
kwargs = {}
kwargs['object_id'] = id
kwargs['model'] = News
kwargs['template_name'] = 'edit_news.html'
kwargs['post_save_redirect'] = '/'
return update_object(request, **kwargs)