File: models.py

package info (click to toggle)
python-django-rules 3.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 320 kB
  • sloc: python: 1,613; makefile: 5; sh: 3
file content (25 lines) | stat: -rw-r--r-- 663 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from __future__ import absolute_import

from django.conf import settings
from django.db import models

import rules
from rules.contrib.models import RulesModel


class Book(models.Model):
    isbn = models.CharField(max_length=50, unique=True)
    title = models.CharField(max_length=100)
    author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

    def __str__(self):
        return self.title


class TestModel(RulesModel):
    class Meta:
        rules_permissions = {"add": rules.always_true, "view": rules.always_true}

    @classmethod
    def preprocess_rules_permissions(cls, perms):
        perms["custom"] = rules.always_true