-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdocument_image_admin.py
37 lines (30 loc) · 1.1 KB
/
document_image_admin.py
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
26
27
28
29
30
31
32
33
34
35
36
37
from django.contrib import admin
from ...models import DocumentImage
class DocumentImageAdmin(admin.StackedInline):
"""
Admin Interface to for the DocumentImage module.
Inheriting from `admin.StackedInline`.
"""
model = DocumentImage
fields = ["image", "image_tag"]
superuser_fields = ["confirmed"]
readonly_fields = ["image_tag"]
autocomplete_fields = ["document"]
insert_after = "autocomplete_fields"
extra = 0
def get_fields(self, request, obj=None):
"""
Override djangos get_fields function
to add custom superuser fields to the
admin interface if the user has the corresponding
access rights.
:param request: current request
:type request: django.http.request
:param obj: [description], defaults to None
:type obj: django.db.models, optional
:return: custom fields list
:rtype: list[str]
"""
if request.user.is_superuser and self.superuser_fields:
return (self.fields or tuple()) + self.superuser_fields
return super().get_fields(request, obj)