不幸的是,Django没有超级魔法Drupal的模拟视频模块https://www.drupal.org/project/views(顺便说一下其他cms也没有它)所以我们都需要写视图代码和添加内容过滤器,就像每个人手动在Django Admin中看到的那样。
我需要在基于类的视图中为Datefield字段添加具有Charfield和datepopup小部件的下拉列表的过滤器,我找到了此http://django-filter.readthedocs.org/en/latest/usage.html的django-filter
但在文档中没有示例如何使用CBW设置它,只有功能视图。
views.py:
#define D_SCL_SECURE_NO_WARNINGS 1
我想轻松添加此过滤器:
class VkwallpostListView(ListView):
model = Vkwallpost
context_object_name = "vk_list"
def get_template_names(self):
return ["vk_list.html"]
def get_context_data(self, **kwargs):
articles = Vkwallpost.objects.order_by("-date_created")[:5]
videos = Fbpagepost.objects.order_by("-date_created")[:5]
items = list(articles) + list(videos)
items.sort(key=lambda i: i.date_created, reverse=True)
return {"vk_fb_list": items[:5]}
def get_queryset(self):
wallposts = Vkwallpost.objects
if 'all_posts' not in self.request.GET:
pass
elif 'all' in self.request.GET:
pass
else:
success = False
criteria = {}
if 'sentiment' in self.request.GET:
criteria['sentiment'] = self.request.GET['sentiment']
print(criteria)
wallposts = wallposts.filter(**criteria)
return wallposts
如何实现这一目标?