MCPcopy
hub / github.com/django/django / get_object

Method get_object

django/contrib/admin/options.py:951–966  ·  view source on GitHub ↗

Return an instance matching the field and value provided, the primary key is used if no field is provided. Return ``None`` if no match is found or the object_id fails validation.

(self, request, object_id, from_field=None)

Source from the content-addressed store, hash-verified

949 )
950
951 def get_object(self, request, object_id, from_field=None):
952 """
953 Return an instance matching the field and value provided, the primary
954 key is used if no field is provided. Return ``None`` if no match is
955 found or the object_id fails validation.
956 """
957 queryset = self.get_queryset(request)
958 model = queryset.model
959 field = (
960 model._meta.pk if from_field is None else model._meta.get_field(from_field)
961 )
962 try:
963 object_id = field.to_python(object_id)
964 return queryset.get(**{field.name: object_id})
965 except (model.DoesNotExist, ValidationError, ValueError):
966 return None
967
968 def get_changelist_form(self, request, **kwargs):
969 """

Callers 4

_changeform_viewMethod · 0.95
_delete_viewMethod · 0.95
history_viewMethod · 0.95
user_change_passwordMethod · 0.45

Calls 4

get_querysetMethod · 0.45
get_fieldMethod · 0.45
to_pythonMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected