1
class Application(models.Model):
    name = models.CharField(max_length=100)
    icon_url = models.CharField(max_length=100)
    app_url = models.CharField(max_length=200)

I would like to add another field for required_permission which should be a foreign key to a permission. What should that field definition look like?

The reasoning behind this is that in a template, I can use something like this (psuedo code)

{% for app in application_list %}
    {% if user_has_permission(app.required_permission) %}
        Show App
    {% endif %}
{% endfor %}
Jacob Valenta
  • 6,659
  • 8
  • 31
  • 42

1 Answers1

0

Your required_permission can be a CharField. As long as you can create a list of permissions to use with this function.

has_perms(perm_list, obj=None)
Returns True if the user has each of the specified permissions, where each perm is in the format "<app label>.<permission codename>". If the user is inactive, this method will always return False.

If obj is passed in, this method won’t check for permissions for the model, but for the specific object.

Note that you can't call function that takes parameter in Django templates, You should write a template tag.

Bibhas Debnath
  • 14,559
  • 17
  • 68
  • 96