我正在开发一个django应用程序,人们可以在其中输入他们的ID,并且他们或者获得他们的活跃客户。
已经解决了,我想要的是每次尝试输入他们的ID时保存
这是观点:
def ingreso_cliente(request):
query_string = ''
found_entries = None
activo = None
#sin buscar
retorno = '3'
today=datetime.now
if ('idcliente' in request.GET) and request.GET['idcliente'].strip():
#filtro por el usuario
query_string = request.GET['idcliente']
entry_query = get_query(query_string, ['cliente__ci'])
#filtro por el mes
found_entries = Pagos.objects.filter(entry_query).order_by('cliente__ci')
activo = found_entries.filter(Q(mes_desde__lte=today)&Q(mes_hasta__gte=today))
if (not activo):
#deudor
retorno = '2'
else:
#activo
retorno = '1'
return render_to_response('ingreso_cliente.html', { 'retorno':retorno, 'today':today }, context_instance=RequestContext(request))
这是我用来输入客户端ID的模板,如果他是否有效,我会得到:
<form method="get" action="/home/ingreso_cliente/">
<input type="text" name="idcliente" id="idcliente"/>
<input type="submit" value="Buscar"/>
</form>
hora: {{today}}
{% if retorno == '1' %}
<span>Cliente Activo</span>
{% elif retorno == '2'%}
<span>Cliente Deudor</span>
{% endif %}
它是一个get请求,并且要保存在db中我需要一个POST,但是使用POST我无法从db中获取数据以了解它是否处于活动状态。有没有办法做到这一点?
答案 0 :(得分:1)
如果您通过GET或POST提交表单没有任何区别。
在您的观看结束时(return
之前),执行以下操作:
LoginAttempt.objects.create(username=query_string, active=retorno)
其中LoginAttempt
是保存登录尝试的模型。这不是理想的,但你明白了,可以使用logging
界面或任何你想记录的尝试。
PS。您的表单也可以在POST中完美地使用,但很明显,您需要在idcliente
而不是request.POST
request.GET
值