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: class AssetViewSet(ModelViewSet):
serializer_class = AssetSerializer
lookup_field = 'slug'
class Asset(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. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Is it possible to hide the numerical ID and instead display a slug or UUID, similar to how DRF uses lookup_field?
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:**
Beta Was this translation helpful? Give feedback.
All reactions