我有一个清晰的表格,我想从数据库中显示额外的上下文。从我所看到的......def get_queryset(self)
没有被调用。
表格.py:
class LoginForm(AuthenticationForm, ListView):
def __init__(self, *args, **kwargs):
super(LoginForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.label_class = 'col-lg-2'
self.helper.field_class = 'col-lg-8'
self.helper.form_tag = False
self.helper.layout = Layout(
Field('username', placeholder="SSO", css_class='input-xlarge'),
Field('password', placeholder="Password", css_class='input-xlarge'),
FormActions(
Submit('login', 'Login', css_class="btn-primary"),
)
)
model = Request
template_name = 'requests_app/requests_list.html'
def get_queryset(self):
print "hi"
return Request.objects.all()
注册/login.html:
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block body %}
<div class="container" style="padding-bottom: 70px;">
<div class='row'>
<div class='col-md-6 col-md-offset-3'>
<div class="well">
<legend>Sign in to Chrono</legend>
<form method="post" action="{% url 'django.contrib.auth.views.login' %}" class="form-horizontal">
{% crispy form %}
<input type="hidden" name="next" value="{{ next }}"/>
</form>
</div>
</div>
</div>
</div>
{% include 'requests_app/request_list.html' %}
{% endblock %}
requests_app/requests_list.html:
<div class="span6">
<ul class="list-group">
{% if object_list %}
{% for item in object_list %}
<li class="list-group-item">{{item.date_due}} - {{item.desctription}}
<span class="badge">
{% if item.user_assigned %}
<span class="badge"style="color:green"> assigned </span>
{% else %}<span class="badge" style="color:red">unassigned</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% else %}
<p>Yay! No maintenance requests found!</p>
{% endif %}
</div>