Doubts in Python - User parameters in query - Mapper in python

0

Friends of Stackoverflow I am an empirical developer in python and I am doing an application where there is an Administrator and several users, the Administrator assigns a certain amount of records to the operator, he sees them in a list and selects one of them, and modify the information and end it back and save everything to the base

I have two problems, the first is in the views.py when I do the query as I do so that it takes the data of which user is assigned and only shows those of the authenticated user. this is my

Views.py

def asignacion(request):
conteo_asig = Cuenta.objects.all().filter(ESTADO_INTERNO='ASIGNADO').count()
conteo_liq = Cuenta.objects.all().filter(ESTADO_INTERNO='LIQUIDADO').count()
conteo_rea = 
Cuenta.objects.all().filter(ESTADO_INTERNO='REASIGNADO').count()
conteo_hoy = Cuenta.objects.all().filter(
  FECHAR_LIQUIDA__gte=datetime.date.today()).count()
cuenta = Cuenta.objects.all().filter(ESTADO_INTERNO='ASIGNADO')
contexto = {'cuentas': cuenta, 'title': 'Mis Cuentas', 'asigna_count': conteo_asig,
  'liquida_count': conteo_liq, 'reasigna_count': conteo_rea, 'hoy_count': conteo_hoy}
assert isinstance(request, HttpRequest)
return render(request, 'liquidacion/asignacion.html', contexto)

That's how I call the assignment of each operator

assignment.html

{% extends "liquidacion/layout.html" %}

{% block content %}


 <div class="py-5" >
<div class="container">
  <div class="row">
    <div class="col-md-12">
      <h1 class="">Mis Cuentas</h1>
    </div>
  </div>

  <div class="row">
    <div class="col-md-6">
      <p class="">Aqui podra usted consultar, re liquidar y organizar las cuentas que han pasado por su usuario. </p>
       <ul class="col-md-4 list-group "  >
        <li class="list-group-item text-center d-flex justify-content-between align-items-center inline"> Cuentas Realizadas Hoy
          <span class="badge badge-primary badge-pill">{{ hoy_count }} </span></ul>


    </div>
    <div class="col-md-6">
      <div class="col-md-12">
        <ul class="list-group" >
          <a href="{% url 'asignacion' %}">
        <li class="list-group-item d-flex justify-content-between align-items-center"> Cuentas Asignadas
          <span class="badge badge-primary badge-pill">{{ asigna_count }} </span>
        </li></a>
        <a href="{% url 'reasignada' %}">
        <li class="list-group-item d-flex justify-content-between align-items-center"> Cuentas Re Asignadas
          <span class="badge badge-primary badge-pill">{{ reasigna_count }}</span>
        </li></a>
       <a href="{% url 'liquidada' %}">
        <li class="list-group-item d-flex justify-content-between align-items-center"> Cuentas Liquidadas
          <span class="badge badge-primary badge-pill">{{ liquida_count }}</span>
        </li></a>
      </ul>            

      </div>
    </div>
  </div>
  <br></br>

  <div class="row">
    <div class="col-md-12">
           {% if cuentas %}

    <div class="table-responsive">
      <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
              <thead class="card-header" >
          <tr>
            <th>#</th>
            <th>NINID</th>
            <th>Radicado</th>
            <th>Factura</th>
            <th>Prestador</th>
            <th>Documento</th>
            <th>Servicio</th>
            <th>Valor</th>
            <th>Tipo Recobro</th>
            <th>Accion</th>
          </tr>
        </thead>
        <tbody>


          {% for cuenta in cuentas %}
          <tr>
            <td>{{cuenta.id}}</td>
            <td>{{cuenta.NIN_ID}}</td>
            <td>{{cuenta.NIN_NRORADICA}}</td>
            <td>{{cuenta.NIN_NROFACT}}</td>
            <td>{{cuenta.NIN_NOM_IPS}}</td>
            <td>{{cuenta.NIN_AFI_IDENTIFIC}}</td>
            <td>{{cuenta.NIN_MAPIISS_DESCRIPCION}}</td>
            <td>{{cuenta.NIN_VALOR_NOPOS}}</td>
            <td>{{cuenta.NIN_TIPANEXO_AUTORIZACION}}</td>
            <td> <a href="{% url 'liquidacuenta' cuenta.id  cuenta.NIN_NRORADICA %}">
            <i class="fa fa-check" aria-hidden="true"></i>Ir </a></td>
          </tr> 
          {% endfor %}
           </tbody>
         </table>
   </div>
         {% else %}
      <div class="table-responsive">
      <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
              <thead class="card-header" >
          <tr>
            <th>#</th>
            <th>NINID</th>
            <th>Radicado</th>
            <th>Factura</th>
            <th>Prestador</th>
            <th>Documento</th>
            <th>Servicio</th>
            <th>Valor</th>
            <th>Tipo Recobro</th>
            <th>Accion</th>
          </tr>
        </thead>
        <tbody>





        </tbody>

      </table>

      {% endif %}


    </div>
  </div>
</div>
 </div>
  {% endblock %}

Urls.py Application

path('asignacion/', views.asignacion, name='asignacion'),
    
asked by Andres Fofo Ramos 09.08.2018 в 21:46
source

1 answer

0

To get all the records of an authenticated user you can try to do the following:

cuenta = Cuenta.objects.filter(<id_usuario>=request.user.pk, ESTADO_INTERNO='ASIGNADO') 
  

Where "user_id" is the name of the id field of your user table and request.user.pk, is the ID of the user logged in.

    
answered by 10.08.2018 / 18:14
source