Skip to content

Commit

Permalink
fix: fix a bug in ContactMessageSerializers
Browse files Browse the repository at this point in the history
  • Loading branch information
AmooHashem committed Jun 16, 2024
1 parent 5cdb0a2 commit f1e16a7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions apps/contact/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models


class ContactMessage(models.Model):
subject = models.TextField()
text = models.TextField()
Expand Down
3 changes: 2 additions & 1 deletion apps/contact/seriallizers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from rest_framework import serializers
from .models import *


class ContactMessageSerializers(serializers.ModelSerializer):
class Meta:
model = ContactMessage
field = ['id', 'object' , 'text', 'email']
fields = ['id', 'object', 'text', 'email']
text = serializers.CharField(required=False)
12 changes: 7 additions & 5 deletions apps/contact/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .models import *
from .seriallizers import ContactMessageSerializers
from rest_framework import viewsets
from rest_framework import viewsets
from rest_framework.response import Response
from rest_framework import status
from rest_framework.permissions import AllowAny
Expand All @@ -10,13 +10,15 @@ class ContactMessageView(viewsets.ModelViewSet):
queryset = ContactMessage.objects.all()
serializer_class = ContactMessageSerializers
permission_classes = [AllowAny]
def get(self , request):

def get(self, request):
data = ContactMessage.object.all()
serializer = ContactMessageSerializers(data , many=True)
serializer = ContactMessageSerializers(data, many=True)
return Response(serializer.data)
def Post(self , request):

def Post(self, request):
serializer = ContactMessageSerializers(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data , status=status.HTTP_200_OK)
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(status=status.HTTP_400_BAD_REQUEST)

0 comments on commit f1e16a7

Please sign in to comment.