Return the natural key for a ForeignKey's related object, or None if not supported.
(self, obj, field)
| 217 | return None |
| 218 | |
| 219 | def _resolve_fk_natural_key(self, obj, field): |
| 220 | """ |
| 221 | Return the natural key for a ForeignKey's related object, or None if |
| 222 | not supported. |
| 223 | """ |
| 224 | if not self._model_supports_natural_key(field.remote_field.model): |
| 225 | return None |
| 226 | |
| 227 | related = getattr(obj, field.name, None) |
| 228 | try: |
| 229 | return related.natural_key() |
| 230 | except AttributeError: |
| 231 | return None |
| 232 | |
| 233 | def _model_supports_natural_key(self, model): |
| 234 | """Return True if the model defines a natural_key() method.""" |
no test coverage detected