Skip to content

Commit 8ea97aa

Browse files
author
Carlton Gibson
committed
Remove Django 1.5 get_model_name fallback
1 parent 4a1ab3c commit 8ea97aa

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

rest_framework/compat.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,6 @@ def clean_manytomany_helptext(text):
127127
pass
128128

129129

130-
def get_model_name(model_cls):
131-
try:
132-
return model_cls._meta.model_name
133-
except AttributeError:
134-
# < 1.6 used module_name instead of model_name
135-
return model_cls._meta.module_name
136-
137-
138130
# MinValueValidator, MaxValueValidator et al. only accept `message` in 1.8+
139131
if django.VERSION >= (1, 8):
140132
from django.core.validators import MinValueValidator, MaxValueValidator

rest_framework/filters.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
from django.db import models
1212
from django.utils import six
1313

14-
from rest_framework.compat import (
15-
distinct, django_filters, get_model_name, guardian
16-
)
14+
from rest_framework.compat import distinct, django_filters, guardian
1715
from rest_framework.settings import api_settings
1816

1917
FilterSet = django_filters and django_filters.FilterSet or None
@@ -202,7 +200,7 @@ def filter_queryset(self, request, queryset, view):
202200
model_cls = queryset.model
203201
kwargs = {
204202
'app_label': model_cls._meta.app_label,
205-
'model_name': get_model_name(model_cls)
203+
'model_name': model_cls._meta.model_name
206204
}
207205
permission = self.perm_format % kwargs
208206
if guardian.VERSION >= (1, 3):

rest_framework/permissions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
from django.http import Http404
77

8-
from rest_framework.compat import get_model_name
9-
108
SAFE_METHODS = ('GET', 'HEAD', 'OPTIONS')
119

1210

@@ -104,7 +102,7 @@ def get_required_permissions(self, method, model_cls):
104102
"""
105103
kwargs = {
106104
'app_label': model_cls._meta.app_label,
107-
'model_name': get_model_name(model_cls)
105+
'model_name': model_cls._meta.model_name
108106
}
109107
return [perm % kwargs for perm in self.perms_map[method]]
110108

@@ -166,7 +164,7 @@ class DjangoObjectPermissions(DjangoModelPermissions):
166164
def get_required_object_permissions(self, method, model_cls):
167165
kwargs = {
168166
'app_label': model_cls._meta.app_label,
169-
'model_name': get_model_name(model_cls)
167+
'model_name': model_cls._meta.model_name
170168
}
171169
return [perm % kwargs for perm in self.perms_map[method]]
172170

0 commit comments

Comments
 (0)