[英]'function' object has no attribute 'objects' Django 1.8 searching a model
I'm getting this error: 我收到此错误:
Exception Type: AttributeError
Exception Value:
'function' object has no attribute 'objects'
web/views.py in consultarE, line 153
from this: 由此:
views.py 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 urls.py
url(r'^consultarEmpleado/$','consultarE',name='consultarEmpleado'),
consultarEmpleado.html 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%}
Check if there's a function called Empleado
which overwrite reference to Empleado
model. 检查是否有一个名为Empleado
的函数,该函数会覆盖对Empleado
模型的引用。
def Empleado(...):
....
Adjust the function name not to conflict with the model name. 调整功能名称不要与型号名称冲突。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.