manosim / manosim/django-rest-framework-docs

setting the fields description if you are using function based views

Open
#119 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
641
Forks
178
PR merge metrics
No merged PRs in 30d

Description

How do I set the field descriptions in views.py on function based views?

**This is my syntax:**
@api_view(['GET', 'POST'])
def api_section(request):
"""
GET request gets the section and its details..... POST request, adds a new section
"""
if request.method == 'GET':
sections = Section.objects.all()
serializer = SectionSerializer(sections, many=True)
return Response(serializer.data)

```
elif request.method == 'POST':
serializer = SectionSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
serializer_data = serializer.data
del serializer_data['id']
return Response(serializer_data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
```

Field descriptions seems to work smoothly by declaring a serializer_class variable in class-based views that inherits APIView like this one:

class ObtainAuthToken(APIView):
throttle_classes = ()
permission_classes = ()
parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
renderer_classes = (renderers.JSONRenderer,)
serializer_class = AuthTokenSerializer

```
def post(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
user = serializer.validated_data['user']
token, created = Token.objects.get_or_create(user=user)
return Response({'token': token.key})
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the views.py function-based example using @api_view and compare it with the APIView serializer_class example in the issue. Review the relevant documentation entry points and determine what guidance is needed for field descriptions in function-based views; done means the supported approach is documented clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
api, backend, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.