Đã giải quyết: người dùng nhân viên không hạn chế quyền trong django

Vấn đề chính của việc không hạn chế quyền là nó có thể dẫn đến việc người dùng có thể làm những việc mà lẽ ra họ không thể làm. Ví dụ: nếu người dùng có quyền chỉnh sửa bài đăng, họ cũng có thể xóa bài đăng đó.

I have a problem with Django. I am using Django 1.8 and Python 3.4. I have created a superuser and staff user in my project, but the staff user is not restricting permission in django admin panel. 
I want to restrict the staff user from accessing some of the models in django admin panel, but it is not working for me, please help me out with this issue.


A:

You should add <code>is_staff = True</code> to your User model: https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django-contrib-admin-models-logentry
<blockquote>
<p>The LogEntry model has two required fields:</p>
<ul>
<li><strong><code>&lt;code&gt;user&lt;/code&gt;</code></strong>: The User that performed the action.</li>
<li><strong><code>&lt;code&gt;action_time&lt;/code&gt;</code></strong>: The timestamp of the action.</li>
</ul>
<p>[...]</p>
<p>[...] If you want to log actions performed by non-staff users, you’ll need to set <a href="https://docs.djangoproject.com/en/1.8/_modules/django/contrib/auth/#User" rel="nofollow noreferrer"><strong><em><a href="https://docs.djangoproject.com/en/1.8/_modules/" rel="nofollow noreferrer">User.<strong></strong>.is_staff</a></em></strong></a>] to True.</p>
</blockquote>

Quyền trong Django

Quyền trong Django là một cách để kiểm soát ai có thể làm gì với ứng dụng của bạn. Chúng được xác định trong tệp permissions.py và có thể được đặt trên cơ sở mỗi người dùng hoặc mỗi ứng dụng.

Quyền có thể được đặt ở cấp độ quyền, đọc hoặc ghi. Mức độ quyền cũng có thể được đặt để cho phép tất cả người dùng, chỉ người dùng ở một vai trò nhất định hoặc chỉ người dùng có quyền nhất định.

Bạn cũng có thể sử dụng biến môi trường DJANGO_SETTINGS_MODULE để đặt quyền cho tất cả các yêu cầu do ứng dụng của bạn thực hiện.

bài viết liên quan:

Để lại một bình luận