I have a list of clients on the responsible screen, in case he presses to deny the client, opens a modal with the field Reason to fill it. I want to get what was typed in this field and save it to the Profile_Post table in the database. However, it's not a form, how do I do it?
In addition, I need to pick up also to save the id of the denied client and that of the logged in user who denied
views.py
def usuarios_autorizar(request, value=None, user_id=None):
user = Perfil.objects.get(pk=request.user.id)
title = "Usuarios nao autorizados"
grupo_responsavel = Grupo.objects.filter(responsavel=user.id)
usuarios = Perfil.objects.filter(grupos__in=grupo_responsavel, is_staff=False)
context = {'lista_usuarios': usuarios}
return render(request, 'usuarios_autorizar.html', context)
def negar(request, item_id):
# para negar
user = User.objects.get(id=item_id)
user.is_staff = False
user.save()
# historico
historico = Historico_Perfil.objects.create()
quem = User.objects.get(id=item_id)
print(quem.id)
historico.usuario = quem.id
historico.data = datetime.now()
historico.acao = "Negado"
historico.save()
return redirect("/cadastro/quantities")
models.py
class Historico_Perfil(models.Model):
acao = models.CharField(max_length=255)
motivo = models.CharField(max_length=255, blank=True)
data = models.DateField(default=datetime.now, blank=True)
usuario = models.ForeignKey(User)
responsavel = models.ForeignKey(User)
html
<table class="striped" id="cadastrados">
<thead>
<tr>
<th>Nome</th>
<th>Telefone</th>
<th>Ramal</th>
<th>Grupo</th>
<th>Autorizar</th>
<th>Negar</th>
</tr>
</thead>
{% for item in lista_usuarios %}
<tr>
<td>{{ item.first_name }}</td>
<td>{{ item.telefone }}</td>
<td>{{ item.ramal }}</td>
<td>{{ item.grupos }}</td>
<td id="autorizado"><a href="{% url 'cadastro:autorizar' item.id %}"
class="btn-floating waves-effect waves-light blue">
<i class="large material-icons">mode_edit</i>
</a>
</td>
<td id="negado"><a href="#modal1"
class="btn-floating waves-effect waves-light blue">
<i class="large material-icons">clear</i>
</a>
</td>
</tr>
</li>
<div id="modal1" class="modal">
<div class="modal-content">
<h4>Motivo</h4>
<textarea id="motivo" class="materialize-textarea"></textarea>
</div>
<div class="modal-footer">
<a href="{% url 'cadastro:negar' item.id %}" class="modal-action modal-close waves-effect waves-blue btn-flat blue">Enviar</a>
</div>
</div>
{% endfor %}
</table>
</div>