Skip to content

Commit 12c6252

Browse files
author
“Muhammad”
committed
change some bugs
1 parent e424c6b commit 12c6252

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Docs for Habib Ilm API Project
2+
3+
This is a habib education api project that used many libraries
4+
in my project.First I connected the backend to the database
5+
and I wrote codes in backend part as API. I used two frames.
6+
The first framework was Django and the second framework was DRF - (Django Rest Framework)
7+
I think that's all.

apps/admins/serializers.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from django.contrib.auth.hashers import make_password
2-
from django.contrib.auth.models import User
2+
from django.contrib.auth.models import User, update_last_login
33
from django.db.transaction import atomic
44
from rest_framework.exceptions import ValidationError
55
from rest_framework.fields import CharField
6-
from rest_framework.serializers import Serializer
6+
from rest_framework.serializers import Serializer, ModelSerializer
7+
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
8+
from rest_framework_simplejwt.settings import api_settings
79

810

911
class RegistrationSerializer(Serializer):
@@ -17,7 +19,7 @@ def validate(self, data):
1719
if User.objects.filter(username=data['username']).exists():
1820
raise ValidationError("This username already taken")
1921
if data['password'] != data['confirm_password']:
20-
raise ValidationError({"password':'Password fields didn't match"})
22+
raise ValidationError({'password': 'Password fields did not match'})
2123
return data
2224

2325
@atomic
@@ -31,3 +33,11 @@ def create(self, validated_data):
3133
class Meta:
3234
model = User
3335
fields = ['id', 'first_name', 'last_name', 'username', 'password']
36+
37+
38+
class UserDataSerializer(ModelSerializer):
39+
class Meta:
40+
model = User
41+
fields = ('id', 'first_name', 'last_name', 'username', 'password')
42+
43+

apps/admins/views.py

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from rest_framework.generics import GenericAPIView
33
from rest_framework.permissions import IsAdminUser, IsAuthenticated
44
from rest_framework.response import Response
5+
from rest_framework.views import APIView
6+
from rest_framework_simplejwt.tokens import RefreshToken
7+
from rest_framework_simplejwt.views import TokenObtainPairView
58

69
from apps.admins.serializers import RegistrationSerializer
710

@@ -16,3 +19,4 @@ def post(self, request):
1619
serializer.save()
1720
return Response(serializer.data, status.HTTP_201_CREATED)
1821
return Response(serializer.errors, status.HTTP_400_BAD_REQUEST)
22+

apps/user/models.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class CourseCategory(BaseModel):
1313
photo = ImageField(upload_to='icons/')
1414

1515
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
16+
if force_update is True:
17+
self.name = slugify(self.name)
1618
self.slug = slugify(self.name)
17-
self.name = slugify(self.name)
18-
1919
super().save(force_insert, force_update, using, update_fields)
2020

2121
def __str__(self):

0 commit comments

Comments
 (0)