When grabbing a models "ID", should probably be using model.pk - https://docs.djangoproject.com/en/dev/ref/models/instances/#the-pk-property.
A models id field is accessable through .pk, as the models PK is always accessible there. When dealing with custom PKs, this causes drf-spectacular to fall over a AttributeError: type object 'MethodCall' has no attribute 'id' error.
For example, I have a model as follows:
class MethodCall(models.Model):
transaction = models.OneToOneField('Transaction', primary_key=True, on_delete=models.CASCADE)
...
As the transaction field has primary_key=True, Django doesn't generate a .id field. However transaction is still accessable via .pk.
This is where it's an issue for me:
|
return self._map_model_field(get_field_from_model(field.model, field.model.id)) |
It may also be an issue here:
|
get_field_from_model(model, model.id) |
When grabbing a models "ID", should probably be using
model.pk- https://docs.djangoproject.com/en/dev/ref/models/instances/#the-pk-property.A models
idfield is accessable through.pk, as the models PK is always accessible there. When dealing with custom PKs, this causes drf-spectacular to fall over aAttributeError: type object 'MethodCall' has no attribute 'id'error.For example, I have a model as follows:
As the
transactionfield hasprimary_key=True, Django doesn't generate a.idfield. Howevertransactionis still accessable via.pk.This is where it's an issue for me:
drf-spectacular/drf_spectacular/openapi.py
Line 359 in bca26d3
It may also be an issue here:
drf-spectacular/drf_spectacular/openapi.py
Line 399 in bca26d3