- Notifications
You must be signed in to change notification settings - Fork302
-
Hi, python
Desired outcome
Try as indicated in the documentation. **Overwriting the resource object’s id Per default the primary key property pk on the instance is used as the resource identifier. It is possible to overwrite the resource id by defining an id field on the serializer like:**
|
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 2 replies
-
This is a fairly recent feature, so you need to make sure that you have at least version 6.1.0 installed. Then in your case, something like the following should work: classAssetViewSet(ModelViewSet):serializer_class=AssetSerializerlookup_field='slug'classAsset(models.Model):id=models.SlugField(max_length=36,unique=True,editable=False,source='slug')name=models.CharField(max_length=50) Have a try and see how it works. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Magnificent, thank you@sliverc |
BetaWas this translation helpful?Give feedback.
All reactions
-
Not 100% sure what you are trying to accomplish. However, Django REST framework JSON:API simply expects a serializer field with the name |
BetaWas this translation helpful?Give feedback.