Bhupesh-V / Bhupesh-V/tutorialdb

Remove duplicate code from app & api

Open
#8 2 comments 0 reactions 0 assignees View on GitHub
enhancement ⭐ good first issue help wanted 🙌
Dominant language
Python
Stars
128
Forks
65
PR merge metrics
No merged PRs in 30d

Description

Currently the implementation of updating the db is almost the same in `app` & `api`
```python
def post(self, request):
linkCount = tutorial.objects.filter(link = request.POST['tlink']).count()
if linkCount == 0:
tags, title = generateTags(request.POST['tlink'])
if 'other' in tags:
return render(request, 'contribute.html', {'error': "Not a Tutorial Link, Try Again"})
else:
tutorialObject = tutorial.objects.create(
title = title,
link = request.POST['tlink'],
category = request.POST['tcategory']
)
for t in tags:
obj, created = tag.objects.get_or_create(name=t)

tagObjList = tag.objects.filter(name__in = tags)
tutorialObject.tags.set(tagObjList)
```

A possible solution is to shift this post method in `serializers.py`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.