Server IP : 66.29.132.122 / Your IP : 3.147.63.2 Web Server : LiteSpeed System : Linux business142.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : admazpex ( 531) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/opt/cloudlinux/venv/lib64/python3.11/site-packages/pylint_django/tests/input/ |
Upload File : |
""" Checks that Pylint does not complain about various methods on many-to-many relationships """ from django.contrib.auth.models import AbstractUser, Permission # pylint: disable=missing-docstring from django.db import models class Book(models.Model): name = models.CharField(max_length=100) good = models.BooleanField(default=False) class Author(models.Model): name = models.CharField(max_length=100) wrote = models.ManyToManyField(Book, verbose_name="Book", related_name="books") def get_good_books(self): return self.wrote.filter(good=True) def is_author_of(self, book): return book in list(self.wrote.all()) def wrote_how_many(self): return self.wrote.count() # Custom permissions for CustomUser USER_PERMS = ["change_customuser", "add_customuser"] class CustomUser(AbstractUser): # pylint: disable=model-no-explicit-unicode class Meta: verbose_name = "CustomUser" verbose_name_plural = "CustomUsers" app_label = "users" def grant_permissions(self): """Example adding permissions to User""" self.user_permissions.clear() for perm in USER_PERMS: perm = Permission.objects.get(codename=perm) self.user_permissions.add(perm) return self.user_permissions def add_permission(self, permission): self.user_permissions.add(permission) def remove_permission(self, permission): self.user_permissions.remove(permission) def set_permissions(self, permissions): self.user_permissions.set(permissions) def save(self, *args, **kwargs): """Saving while granting new permissions""" self.is_staff = True super().save() self.grant_permissions()