0
How can I change the urls in rest_framework on Django?
The router defaults to using the creature ID in the URL ex. /api/Creatures/1/
I want instead of appearing the ID, appear the name of the creature.
ex. /api/Creature/dragon/
serializer.py
class CreatureSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Creature
fields = ['url', 'name', 'experience', 'level', 'description', 'resistance', 'drop', 'rare_drop']
py router.
router = routers.DefaultRouter()
router.register(r'creatures', CreatureViewSet, basename='creature')
urlpatterns = [
path('', include(router.urls)),
]
Where do I put this Lug field? In the Viewset itself?
– Thomas Caio
Could not resolve URL for hyperlinked Relationship using view name "Creature-Detail". You may have failed to include the Related model in your API, or incorrectly configured the
lookup_field
attribute on this field. to with this problem now– Thomas Caio