我收到了这个错误:
Exception Type: AttributeError
Exception Value:
'function' object has no attribute 'objects'
web/views.py in consultarE, line 153
来自:
views.py
def consultarE(request):
query = request.GET.get('q', '')
if query:
qset = (
Q(nombres__icontains=query) |
Q(apellidos__icontains=query) |
Q(telefono__icontains=query)
# Q(cargo__icontains=query)
)
results = Empleado.objects.filter(qset).distinct()
else:
results = []
return render_to_response("web/consultarEmpleado.html", {
"results": results,
"query": query
})
urls.py
url(r'^consultarEmpleado/$','consultarE',name='consultarEmpleado'),
consultarEmpleado.html
{% block content%}
<h1>Ingrese su búsqueda</h1>
<form class="navbar-form" role="search" action="." method="GET">
{{form|crispy}}
<label for="q">Buscar: </label>
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="q" value="{{ query|escape }}">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
{% if query %}
<h2>Results for "{{ query|escape }}":</h2>
{% if results %}
<ul>
{% for empleado in results %}
<li>{{ empleado|escape }}</l1>
{% endfor %}
</ul>
{% else %}
<p>No se encontró empleado</p>
{% endif %}
{% endif %}
{%endblock%}
答案 0 :(得分:0)
检查是否有一个名为Empleado
的函数覆盖对Empleado
模型的引用。
def Empleado(...):
....
调整功能名称,使其不与型号名称冲突。