mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 01:55:21 +00:00
FAQ list and creation
This commit is contained in:
@ -163,6 +163,8 @@ SUCCESS_CODE = {
|
||||
"3043": "Read article card successfully",
|
||||
# remove guardian code request
|
||||
"3044": "Remove guardian code request successfully",
|
||||
# create faq
|
||||
"3045": "Create FAQ data"
|
||||
|
||||
}
|
||||
"""status code error"""
|
||||
|
@ -3,8 +3,9 @@
|
||||
from django.contrib import admin
|
||||
"""Import Django app"""
|
||||
from .models import (Junior, JuniorPoints, JuniorGuardianRelationship, JuniorArticlePoints, JuniorArticle,
|
||||
JuniorArticleCard)
|
||||
JuniorArticleCard, FAQ)
|
||||
# Register your models here.
|
||||
admin.site.register(FAQ)
|
||||
@admin.register(JuniorArticle)
|
||||
class JuniorArticleAdmin(admin.ModelAdmin):
|
||||
"""Junior Admin"""
|
||||
|
@ -0,0 +1,39 @@
|
||||
# Generated by Django 4.2.2 on 2023-08-17 09:04
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('junior', '0025_alter_juniorarticle_junior'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='FAQ',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('question', models.IntegerField(max_length=100)),
|
||||
('description', models.CharField(max_length=500)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'FAQ',
|
||||
'verbose_name_plural': 'FAQ',
|
||||
},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='juniorarticle',
|
||||
options={'verbose_name': 'Junior Article', 'verbose_name_plural': 'Junior Article'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='juniorarticlecard',
|
||||
options={'verbose_name': 'Junior Article Card', 'verbose_name_plural': 'Junior Article Card'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='juniorarticlepoints',
|
||||
options={'verbose_name': 'Junior Article Points', 'verbose_name_plural': 'Junior Article Points'},
|
||||
),
|
||||
]
|
18
junior/migrations/0027_alter_faq_question.py
Normal file
18
junior/migrations/0027_alter_faq_question.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.2 on 2023-08-17 09:37
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('junior', '0026_faq_alter_juniorarticle_options_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='faq',
|
||||
name='question',
|
||||
field=models.CharField(max_length=100),
|
||||
),
|
||||
]
|
@ -223,7 +223,7 @@ class JuniorArticleCard(models.Model):
|
||||
class FAQ(models.Model):
|
||||
"""FAQ model"""
|
||||
# Total earned points"""
|
||||
questions = models.IntegerField(max_length=100)
|
||||
question = models.CharField(max_length=100)
|
||||
# referral points"""
|
||||
description = models.CharField(max_length=500)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
@ -237,4 +237,4 @@ class FAQ(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
"""Return email id"""
|
||||
return f'{self.questions}'
|
||||
return f'{self.question}'
|
||||
|
@ -12,7 +12,7 @@ from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
# local imports
|
||||
from account.utils import send_otp_email, generate_code
|
||||
from junior.models import Junior, JuniorPoints, JuniorGuardianRelationship, JuniorArticlePoints
|
||||
from junior.models import Junior, JuniorPoints, JuniorGuardianRelationship, JuniorArticlePoints, FAQ
|
||||
from guardian.tasks import generate_otp
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
from base.constants import (PENDING, IN_PROGRESS, REJECTED, REQUESTED, COMPLETED, NUMBER, JUN, ZOD, EXPIRED,
|
||||
@ -508,3 +508,17 @@ class RemoveGuardianCodeSerializer(serializers.ModelSerializer):
|
||||
instance.guardian_code_status = str(NUMBER['one'])
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
class FAQSerializer(serializers.ModelSerializer):
|
||||
# FAQ Serializer
|
||||
|
||||
class Meta(object):
|
||||
# meta info
|
||||
model = FAQ
|
||||
fields = ('id', 'question', 'description')
|
||||
|
||||
def create(self, validated_data):
|
||||
# validate data
|
||||
print("validated_data===>",validated_data)
|
||||
faq = FAQ.objects.bulk_create(**validated_data)
|
||||
return faq
|
||||
|
@ -36,7 +36,7 @@ from junior.models import (Junior, JuniorPoints, JuniorGuardianRelationship, Jun
|
||||
from .serializers import (CreateJuniorSerializer, JuniorDetailListSerializer, AddJuniorSerializer,
|
||||
RemoveJuniorSerializer, CompleteTaskSerializer, JuniorPointsSerializer,
|
||||
AddGuardianSerializer, StartTaskSerializer, ReAssignTaskSerializer,
|
||||
RemoveGuardianCodeSerializer)
|
||||
RemoveGuardianCodeSerializer, FAQSerializer)
|
||||
from guardian.models import Guardian, JuniorTask
|
||||
from guardian.serializers import TaskDetailsSerializer, TaskDetailsjuniorSerializer
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
@ -658,26 +658,28 @@ class FAQViewSet(GenericViewSet, mixins.CreateModelMixin,
|
||||
mixins.ListModelMixin):
|
||||
"""FAQ view set"""
|
||||
|
||||
serializer_class = ArticleSerializer
|
||||
serializer_class = FAQSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
http_method_names = ['get', 'post']
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = FAQ.objects.all()
|
||||
return queryset
|
||||
return FAQ.objects.all()
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""
|
||||
article create api method
|
||||
faq 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"])
|
||||
obj_data = [FAQ(**item) for item in request.data]
|
||||
try:
|
||||
FAQ.objects.bulk_create(obj_data)
|
||||
return custom_response(SUCCESS_CODE["3045"], response_status=status.HTTP_200_OK)
|
||||
except Exception as e:
|
||||
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
"""
|
||||
@ -691,5 +693,8 @@ class FAQViewSet(GenericViewSet, mixins.CreateModelMixin,
|
||||
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)
|
||||
return custom_response(None, data=serializer.data, response_status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -180,32 +180,32 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
# database query logs settings
|
||||
# Allows us to check db hits
|
||||
# useful to optimize db query and hit
|
||||
LOGGING = {
|
||||
"version": 1,
|
||||
"filters": {
|
||||
"require_debug_true": {
|
||||
"()": "django.utils.log.RequireDebugTrue"
|
||||
}
|
||||
},
|
||||
"handlers": {
|
||||
"console": {
|
||||
"level": "DEBUG",
|
||||
"filters": [
|
||||
"require_debug_true"
|
||||
],
|
||||
"class": "logging.StreamHandler"
|
||||
}
|
||||
},
|
||||
# database logger
|
||||
"loggers": {
|
||||
"django.db.backends": {
|
||||
"level": "DEBUG",
|
||||
"handlers": [
|
||||
"console"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
# LOGGING = {
|
||||
# "version": 1,
|
||||
# "filters": {
|
||||
# "require_debug_true": {
|
||||
# "()": "django.utils.log.RequireDebugTrue"
|
||||
# }
|
||||
# },
|
||||
# "handlers": {
|
||||
# "console": {
|
||||
# "level": "DEBUG",
|
||||
# "filters": [
|
||||
# "require_debug_true"
|
||||
# ],
|
||||
# "class": "logging.StreamHandler"
|
||||
# }
|
||||
# },
|
||||
# # database logger
|
||||
# "loggers": {
|
||||
# "django.db.backends": {
|
||||
# "level": "DEBUG",
|
||||
# "handlers": [
|
||||
# "console"
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||
|
Reference in New Issue
Block a user