Setup
I have a standard setup with model Account and corresponding AccountSerializer.
serializers.py:
class AccountSerializer(serializers.ModelSerializer):
class Meta:
model = Account
fields = ('id', 'account_name', 'users', 'created')
views.py:
class SingleAccountView(generics.RetrieveAPIView):
serializer_class = AccountSerializer
queryset = Account.objects.all()
lookup_field = 'id'
permission_classes = ()
urls.py:
url(r'^account/(?P<id>\w+)$', SingleAccountView.as_view())
Goal
I want to be able to access the properties of my serializer by url, without hardcoding them into urls.py. E.g., I want to be able to go to website.com/account/23/account_name to get the account name for account 23. How can I achieve this?