@@ -97,14 +97,10 @@ def register_child(self, model, model_admin):
97
97
raise RegistrationClosed ("The admin model can't be registered anymore at this point." )
98
98
99
99
if not issubclass (model , self .base_model ):
100
- raise TypeError (
101
- "{} should be a subclass of {}" .format (model .__name__ , self .base_model .__name__ )
102
- )
100
+ raise TypeError (f"{ model .__name__ } should be a subclass of { self .base_model .__name__ } " )
103
101
if not issubclass (model_admin , admin .ModelAdmin ):
104
102
raise TypeError (
105
- "{} should be a subclass of {}" .format (
106
- model_admin .__name__ , admin .ModelAdmin .__name__
107
- )
103
+ f"{ model_admin .__name__ } should be a subclass of { admin .ModelAdmin .__name__ } "
108
104
)
109
105
110
106
self ._child_admin_site .register (model , model_admin )
@@ -159,7 +155,8 @@ def _get_real_admin_by_ct(self, ct_id, super_if_self=True):
159
155
model_class = ct .model_class ()
160
156
if not model_class :
161
157
# Handle model deletion
162
- raise Http404 ("No model found for '{}.{}'." .format (* ct .natural_key ()))
158
+ app_label , model = ct .natural_key ()
159
+ raise Http404 (f"No model found for '{ app_label } .{ model } '." )
163
160
164
161
return self ._get_real_admin_by_model (model_class , super_if_self = super_if_self )
165
162
@@ -168,7 +165,7 @@ def _get_real_admin_by_model(self, model_class, super_if_self=True):
168
165
# Hence, make sure this is a derived object, or risk exposing other admin interfaces.
169
166
if model_class not in self ._child_models :
170
167
raise PermissionDenied (
171
- "Invalid model '{}', it must be registered as child model." . format ( model_class )
168
+ f "Invalid model '{ model_class } ', it must be registered as child model."
172
169
)
173
170
174
171
try :
@@ -177,7 +174,7 @@ def _get_real_admin_by_model(self, model_class, super_if_self=True):
177
174
real_admin = self ._child_admin_site ._registry [model_class ]
178
175
except KeyError :
179
176
raise ChildAdminNotRegistered (
180
- "No child admin site was registered for a '{}' model." . format ( model_class )
177
+ f "No child admin site was registered for a '{ model_class } ' model."
181
178
)
182
179
183
180
if super_if_self and real_admin is self :
@@ -273,7 +270,7 @@ def subclass_view(self, request, path):
273
270
object_id = int (path [0 :pos ])
274
271
except ValueError :
275
272
raise Http404 (
276
- "No ct_id parameter, unable to find admin subclass for path '{}'." . format ( path )
273
+ f "No ct_id parameter, unable to find admin subclass for path '{ path } '."
277
274
)
278
275
279
276
ct_id = self .model .objects .values_list ("polymorphic_ctype_id" , flat = True ).get (
@@ -299,7 +296,8 @@ def add_type_view(self, request, form_url=""):
299
296
if request .META ["QUERY_STRING" ]:
300
297
# QUERY_STRING is bytes in Python 3, using force_str() to decode it as string.
301
298
# See QueryDict how Django deals with that.
302
- extra_qs = "&{}" .format (force_str (request .META ["QUERY_STRING" ]))
299
+ # TODO: should this use a Django method instead of manipulating the string directly?
300
+ extra_qs = f"&{ force_str (request .META ['QUERY_STRING' ])} "
303
301
304
302
choices = self .get_child_type_choices (request , "add" )
305
303
if len (choices ) == 0 :
@@ -315,7 +313,7 @@ def add_type_view(self, request, form_url=""):
315
313
form .fields ["ct_id" ].choices = choices
316
314
317
315
if form .is_valid ():
318
- return HttpResponseRedirect ("?ct_id={}{}" . format ( form .cleaned_data [" ct_id" ], extra_qs ) )
316
+ return HttpResponseRedirect (f "?ct_id={ form .cleaned_data [' ct_id' ] } { extra_qs } " )
319
317
320
318
# Wrap in all admin layout
321
319
fieldsets = ((None , {"fields" : ("ct_id" ,)}),)
@@ -351,7 +349,7 @@ def render_add_type_form(self, request, context, form_url=""):
351
349
352
350
templates = self .add_type_template or [
353
351
f"admin/{ app_label } /{ opts .object_name .lower ()} /add_type_form.html" ,
354
- "admin/%s /add_type_form.html" % app_label ,
352
+ f "admin/{ app_label } /add_type_form.html" ,
355
353
"admin/polymorphic/add_type_form.html" , # added default here
356
354
"admin/add_type_form.html" ,
357
355
]
@@ -370,9 +368,9 @@ def change_list_template(self):
370
368
371
369
return [
372
370
f"admin/{ app_label } /{ opts .object_name .lower ()} /change_list.html" ,
373
- "admin/%s /change_list.html" % app_label ,
371
+ f "admin/{ app_label } /change_list.html" ,
374
372
# Added base class:
375
- "admin/%s/%s/change_list.html" % ( base_app_label , base_opts .object_name .lower ()) ,
376
- "admin/%s /change_list.html" % base_app_label ,
373
+ f "admin/{ base_app_label } / { base_opts .object_name .lower ()} /change_list.html" ,
374
+ f "admin/{ base_app_label } /change_list.html" ,
377
375
"admin/change_list.html" ,
378
376
]
0 commit comments