大家好,我正在使用Aldryn Apphooks Config
将配置添加到我的apphook。
我的模特就像这样
class Entry(models.Model):
TYPES_CHOICES = (
('none', 'not specified'),
('v', 'By Visit'),
('p', 'By Patient'),
)
app_config = AppHookConfigField(FaqConfig)
url = models.CharField(blank=True, default='', max_length=250)
count = models.CharField(blank=True, default='', max_length=250)
start = models.CharField(blank=True, default='', max_length=250)
status = models.CharField(choices=TYPES_CHOICES, max_length=10)
我的view.py就像这样
class IndexView(AppConfigMixin, generic.ListView):
model = Entry
template_name = 'faq/index.html'
def get_queryset(self):
qs = super(IndexView, self).get_queryset()
return qs.namespace(self.namespace)
def get_context_data (self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
values_to_pass = context['object_list'].values('url', 'count', 'start')
context['object_list'] = values_to_pass
print context['object_list']
return context
我添加get_context_data来获取参数,但在这种情况下,这将返回一个空列表
如果我返回print context
,我会获得此
{u'paginator': <django.core.paginator.Paginator object at 0x112aeff90>, u'object_list': [], u'page_obj': <Page 1 of 1>, u'entry_list': [], u'is_paginated': False, u'view': <health.views.IndexView object at 0x1124d9f10>}
知道为什么u'object_list
和entry_list
为空,如何获取模型的参数url
,status
和count
知道如何做到这一点
提前致谢
答案 0 :(得分:1)
get_context_data
方法构建上下文以传递给html模板。要更改它,请执行以下操作。
ListView
这会将dicts列表传递给您的html模板,例如class IndexView(AppConfigMixin, generic.ListView):
model = Entry
template_name = 'faq/index.html'
def get_context_data(self, **kwargs):
context = super(MultipleObjectMixin, self).get_context_data(**kwargs)
values_to_pass = context['object_list'].values('url', 'count', 'start')
context['new_object_list'] = values_to_pass
return context