I hope this helps . First: Your urls.py works with the first matched url. So it can not find your second url. Second: In my opinion you should either stick to the "pk" Version (which is what REST states) or the slug version for the lookup. So in general i would anticipate the process of either looking for a pk or a slug.
I wish this help you The pk and/or slug are set in the pre_save method because they're implicit in the URL. (As opposed to the request data, which is handled by the serializer.) If you really need to change the behavior you can do so by overriding the pre_save method, although it's not obvious to me why you need it to do something different.
Django Rest Framework get a lookup field as a list of hyperlinks
fixed the issue. Will look into that further There is the django.utils.text.slugify method. If you want to use it you can simple call slugify() on your title. In a serializer you might want to use it like so:
from django.utils.text import slugify
title_slug = serializers.SerializerMethodField()
def get_title_slug(self, instance):
model = Example
fields = ("title_slug", )
django rest framework access item by lookup field instead of pk 3.4 DRF
fixed the issue. Will look into that further Can an email field in the model be used as a lookup field for the rest api? , specify the lookup_value_regex attribute in the viewset
queryset = Foo.objects.all()
serializer_class = FooSerializer
lookup_field = 'email'
lookup_url_kwarg = 'email'
lookup_value_regex = '[\w@.]+' # here is the new attribute