you can use slug for the url you want to make "api/movies/ghost-busters/scenes"
at first you have to make model with slugField eg.
class Blog(models.Model):
qoute = models.CharField(max_length=30)
slug = models.SlugField()
def save(self, *args, **kwargs):
self.slug = slugify(self.qoute)
super(Blog, self).save(*args, **kwargs)
during the saving model it will create a slug by "qoute" and save to the column "slug"
make your urls.py
entry
url(r'^api/movies/(?P<slug>[\w-]+)/scenes/$', 'myapp.views.blog_detail', name='blog_detail'),
then for the drf you have set lookup_field
in the serializer
and view also.
N.B: you can user ModelSerializer or Serializer or HyperlinkSerialzer as you wish..
class BlogSerializer(serializers.ModelSerializer):
class Meta:
model = Blog
fields = ('quote', 'slug',)
lookup_field = 'slug'
and the views..
class blog_detail(generics.RetrieveUpdateDestroyAPIView):
queryset = Blog.objects.all()
serializer_class = BlogSerializer
lookup_field = 'slug'