django-guardian

Django: Can't override admin templates when they are already overridden?

元气小坏坏 提交于 2019-12-05 21:37:35
To add some content to a Django admin view of a model, I want to override the change_form.html template. According to the documentation I would need to create a file change_form.html in a the folder /project-path/templates/admin/appname/modelname/ . Of course I need to make sure, that this path is also available in TEMPLATE_DIRS . Such a file could look like this: {% extends "admin/change_form.html" %} {% load i18n %} {% block after_field_sets %} SOME CONTENT {% endblock %} However, I make use of django-guardian to have object permissions. This Django app overrides change_form.html as well

How do I define default permissions for users in Django Guardian?

只愿长相守 提交于 2019-12-04 03:33:01
问题 When I create a user in Django, he has no permissions: In [7]: u = User.objects.create(username='aoeu') In [12]: u.user_permissions.all() Out[12]: [] I want some permissions to be set by default (say, 'api.add_item'), and I use Django Guardian. Is this possible to do in a declarative way, eg. without writing a post_save signal? 回答1: No, it is not possible. Check django.contrib.auth code to ensure 来源: https://stackoverflow.com/questions/12312931/how-do-i-define-default-permissions-for-users-in

Can django-guardian and django-rules be used together?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 16:04:16
I'd like to be able to create per-object permissions using django-guardian . But I'd like to add a layer of logic surrounding these permissions. For example if someone has edit_book permission on a Book , then their permission to edit Pages in that book should be implicit. The rules package seems ideal. The following appears to work: import rules import guardian @rules.predicate def is_page_book_editor(user, page): return user.has_perm('books.edit_book', page.book) @rules.predicate def is_page_editor(user, page): return user.has_perm('pages.edit_page', page) rules.add_perm('pages.can_edit_page

How to handle per object permission in Django nowadays?

一曲冷凌霜 提交于 2019-12-02 19:02:48
I was about to use django-guardian until I came across the following in the official documentation: https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#handling-authorization-in-custom-backends Permissions can be set not only per type of object, but also per specific object instance. By using the has_add_permission(), has_change_permission() and has_delete_permission() methods provided by the ModelAdmin class, it is possible to customize permissions for different object instances of the same type. Does that mean django-guardian is no longer needed with newer versions of Django?

How do I define default permissions for users in Django Guardian?

北城余情 提交于 2019-12-01 19:06:14
When I create a user in Django, he has no permissions: In [7]: u = User.objects.create(username='aoeu') In [12]: u.user_permissions.all() Out[12]: [] I want some permissions to be set by default (say, 'api.add_item'), and I use Django Guardian . Is this possible to do in a declarative way, eg. without writing a post_save signal? No, it is not possible. Check django.contrib.auth code to ensure 来源: https://stackoverflow.com/questions/12312931/how-do-i-define-default-permissions-for-users-in-django-guardian