django permission

0

Good afternoon, I'm wanting in the template to make a loop to disable a button according to custom permission. The model code is:

# -*- coding: utf8 -*-
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User

class PermUser(models.Model):
    user = models.OneToOneField(User,on_delete=models.CASCADE)
    tecnico = models.ForeignKey('imuno.Tecnico')

    def __str__(self):
        return ''

    class Meta:
        permissions = (
                       ("SIR", "Somente Imprimir Relatorio"),
                      )

In the template I do:

{% if show_save %}
       {% if perm.permissao.SIR %}
            <button type="submit" title="{% trans 'Save' %}" class="list-group-item disabled" name="_save">
              <span class="glyphicon glyphicon-floppy-disk"></span>
              <span class="text">{% trans 'Save' %}</span>
            </button>
       {% else %}
            <button type="submit" title="{% trans 'Save' %}" class="list-group-item active" name="_save">
              <span class="glyphicon glyphicon-floppy-disk"></span>
              <span class="text">{% trans 'Save' %}</span>
            </button>
       {% endif %}
 {% endif %}

With or without permission, it shows the button if I put "not" with or without permission is disabled. Would anyone know what the mistake was? in the django documentation shows this way of applying the perm call to the template.

    
asked by anonymous 13.03.2017 / 21:36

0 answers