mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 18:36:18 +00:00
FAQ model
This commit is contained in:
@ -252,7 +252,6 @@ def generate_code(value, user_id):
|
||||
|
||||
OTP_EXPIRY = timezone.now() + timezone.timedelta(days=1)
|
||||
|
||||
|
||||
def get_user_full_name(user_obj):
|
||||
"""
|
||||
to get user's full name
|
||||
|
@ -158,6 +158,12 @@ class JuniorArticlePoints(models.Model):
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta(object):
|
||||
""" Meta class """
|
||||
verbose_name = 'Junior Article Points'
|
||||
# another name of the model"""
|
||||
verbose_name_plural = 'Junior Article Points'
|
||||
|
||||
def __str__(self):
|
||||
"""Return title"""
|
||||
return f'{self.id} | {self.question}'
|
||||
@ -178,6 +184,12 @@ class JuniorArticle(models.Model):
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta(object):
|
||||
""" Meta class """
|
||||
verbose_name = 'Junior Article'
|
||||
# another name of the model"""
|
||||
verbose_name_plural = 'Junior Article'
|
||||
|
||||
def __str__(self):
|
||||
"""Return title"""
|
||||
return f'{self.id} | {self.article}'
|
||||
@ -197,6 +209,32 @@ class JuniorArticleCard(models.Model):
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta(object):
|
||||
""" Meta class """
|
||||
verbose_name = 'Junior Article Card'
|
||||
# another name of the model"""
|
||||
verbose_name_plural = 'Junior Article Card'
|
||||
|
||||
def __str__(self):
|
||||
"""Return title"""
|
||||
return f'{self.id} | {self.article}'
|
||||
|
||||
|
||||
class FAQ(models.Model):
|
||||
"""FAQ model"""
|
||||
# Total earned points"""
|
||||
questions = models.IntegerField(max_length=100)
|
||||
# referral points"""
|
||||
description = models.CharField(max_length=500)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta(object):
|
||||
""" Meta class """
|
||||
verbose_name = 'FAQ'
|
||||
# another name of the model"""
|
||||
verbose_name_plural = 'FAQ'
|
||||
|
||||
def __str__(self):
|
||||
"""Return email id"""
|
||||
return f'{self.questions}'
|
||||
|
@ -6,7 +6,7 @@ from .views import (UpdateJuniorProfile, ValidateGuardianCode, JuniorListAPIView
|
||||
CompleteJuniorTaskAPIView, JuniorPointsListAPIView, ValidateReferralCode,
|
||||
InviteGuardianAPIView, StartTaskAPIView, ReAssignJuniorTaskAPIView, StartArticleAPIView,
|
||||
StartAssessmentAPIView, CheckAnswerAPIView, CompleteArticleAPIView, ReadArticleCardAPIView,
|
||||
CreateArticleCardAPIView, RemoveGuardianCodeAPIView)
|
||||
CreateArticleCardAPIView, RemoveGuardianCodeAPIView, FAQViewSet)
|
||||
"""Third party import"""
|
||||
from rest_framework import routers
|
||||
|
||||
@ -51,6 +51,8 @@ router.register('start-assessment', StartAssessmentAPIView, basename='start-asse
|
||||
router.register('check-answer', CheckAnswerAPIView, basename='check-answer')
|
||||
# start article"""
|
||||
router.register('create-article-card', CreateArticleCardAPIView, basename='create-article-card')
|
||||
# FAQ API
|
||||
router.register('faq', FAQViewSet, basename='faq')
|
||||
# Define url pattern"""
|
||||
urlpatterns = [
|
||||
path('api/v1/', include(router.urls)),
|
||||
|
@ -10,6 +10,8 @@ from django.db.models import F
|
||||
|
||||
import datetime
|
||||
import requests
|
||||
|
||||
from rest_framework.viewsets import GenericViewSet, mixins
|
||||
"""Django app import"""
|
||||
|
||||
# Import guardian's model,
|
||||
@ -30,7 +32,7 @@ import requests
|
||||
# Import constants
|
||||
from django.db.models import Sum
|
||||
from junior.models import (Junior, JuniorPoints, JuniorGuardianRelationship, JuniorArticlePoints, JuniorArticle,
|
||||
JuniorArticleCard)
|
||||
JuniorArticleCard, FAQ)
|
||||
from .serializers import (CreateJuniorSerializer, JuniorDetailListSerializer, AddJuniorSerializer,
|
||||
RemoveJuniorSerializer, CompleteTaskSerializer, JuniorPointsSerializer,
|
||||
AddGuardianSerializer, StartTaskSerializer, ReAssignTaskSerializer,
|
||||
@ -650,3 +652,44 @@ class RemoveGuardianCodeAPIView(views.APIView):
|
||||
return custom_error_response(ERROR_CODE['2047'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
except Exception as e:
|
||||
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
class FAQViewSet(GenericViewSet, mixins.CreateModelMixin,
|
||||
mixins.ListModelMixin):
|
||||
"""FAQ view set"""
|
||||
|
||||
serializer_class = ArticleSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
http_method_names = ['get', 'post']
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = FAQ.objects.all()
|
||||
return queryset
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""
|
||||
article create api method
|
||||
:param request:
|
||||
:param args:
|
||||
:param kwargs:
|
||||
:return: success message
|
||||
"""
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
serializer.save()
|
||||
return custom_response(SUCCESS_CODE["3027"])
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
"""
|
||||
article list api method
|
||||
:param request:
|
||||
:param args:
|
||||
:param kwargs:
|
||||
:return: list of article
|
||||
"""
|
||||
queryset = self.get_queryset()
|
||||
paginator = self.pagination_class()
|
||||
paginated_queryset = paginator.paginate_queryset(queryset, request)
|
||||
serializer = self.serializer_class(paginated_queryset, many=True)
|
||||
return custom_response(None, data=serializer.data)
|
||||
|
||||
|
Reference in New Issue
Block a user