Code

Ticket #15809: add_object_has_add_perm.diff

File add_object_has_add_perm.diff, 1.7 KB (added by EnTeQuAk, 3 years ago)
Line 
1Index: docs/ref/contrib/admin/index.txt
2===================================================================
3--- docs/ref/contrib/admin/index.txt    (revision 16025)
4+++ docs/ref/contrib/admin/index.txt    (working copy)
5@@ -954,7 +954,7 @@
6                         kwargs['choices'] += (('ready', 'Ready for deployment'),)
7                 return super(MyModelAdmin, self).formfield_for_choice_field(db_field, request, **kwargs)
8 
9-.. method:: ModelAdmin.has_add_permission(self, request)
10+.. method:: ModelAdmin.has_add_permission(self, request, obj=None)
11 
12     Should return ``True`` if adding an object is permitted, ``False``
13     otherwise.
14Index: django/contrib/admin/options.py
15===================================================================
16--- django/contrib/admin/options.py     (revision 16025)
17+++ django/contrib/admin/options.py     (working copy)
18@@ -347,7 +347,7 @@
19         return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
20     media = property(_media)
21 
22-    def has_add_permission(self, request):
23+    def has_add_permission(self, request, obj=None):
24         """
25         Returns True if the given request has permission to add an object.
26         Can be overriden by the user in subclasses.
27@@ -682,7 +682,7 @@
28         context.update({
29             'add': add,
30             'change': change,
31-            'has_add_permission': self.has_add_permission(request),
32+            'has_add_permission': self.has_add_permission(request, obj),
33             'has_change_permission': self.has_change_permission(request, obj),
34             'has_delete_permission': self.has_delete_permission(request, obj),
35             'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,