MCPcopy
hub / github.com/django/django / contents

Method contents

django/contrib/admin/helpers.py:269–301  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

267 return str(remote_obj)
268
269 def contents(self):
270 from django.contrib.admin.templatetags.admin_list import _boolean_icon
271
272 field, obj, model_admin = (
273 self.field["field"],
274 self.form.instance,
275 self.model_admin,
276 )
277 try:
278 f, attr, value = lookup_field(field, obj, model_admin)
279 except (AttributeError, ValueError, ObjectDoesNotExist):
280 result_repr = self.empty_value_display
281 else:
282 if f is None:
283 if getattr(attr, "boolean", False):
284 result_repr = _boolean_icon(value)
285 else:
286 if hasattr(value, "__html__"):
287 result_repr = value
288 else:
289 result_repr = linebreaksbr(value)
290 else:
291 if isinstance(f.remote_field, ManyToManyRel) and value is not None:
292 result_repr = ", ".join(map(str, value.all()))
293 elif (
294 isinstance(f.remote_field, (ForeignObjectRel, OneToOneField))
295 and value is not None
296 ):
297 result_repr = self.get_admin_url(f.remote_field, value)
298 else:
299 result_repr = display_for_field(value, f, self.empty_value_display)
300 result_repr = linebreaksbr(result_repr)
301 return conditional_escape(result_repr)
302
303
304class InlineAdminFormSet:

Calls 8

get_admin_urlMethod · 0.95
lookup_fieldFunction · 0.90
_boolean_iconFunction · 0.90
linebreaksbrFunction · 0.90
display_for_fieldFunction · 0.90
conditional_escapeFunction · 0.90
joinMethod · 0.45
allMethod · 0.45

Tested by 1