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)
| 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 | """ |
no test coverage detected