Skip to content

Commit

Permalink
feat: 重新修改注册的接口字段
Browse files Browse the repository at this point in the history
  • Loading branch information
LonelyFellas committed Jun 30, 2024
1 parent 31a2332 commit 1917f05
Show file tree
Hide file tree
Showing 19 changed files with 21 additions and 18 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.venv
.vscode
.idea
.idea/*
*.iml
*.xml
__pycache__
venv
# Logs
logs
*.log
Expand Down
3 changes: 2 additions & 1 deletion .idea/djangoProject.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified db.sqlite3
Binary file not shown.
Binary file modified djangoProject/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified djangoProject/__pycache__/settings.cpython-312.pyc
Binary file not shown.
Binary file modified djangoProject/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified djangoProject/__pycache__/wsgi.cpython-312.pyc
Binary file not shown.
Binary file modified user/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified user/__pycache__/admin.cpython-312.pyc
Binary file not shown.
Binary file modified user/__pycache__/apps.cpython-312.pyc
Binary file not shown.
Binary file modified user/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file modified user/__pycache__/serializers.cpython-312.pyc
Binary file not shown.
Binary file modified user/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified user/__pycache__/views.cpython-312.pyc
Binary file not shown.
Binary file modified user/migrations/__pycache__/0001_initial.cpython-312.pyc
Binary file not shown.
Binary file modified user/migrations/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@


class User(AbstractUser):
role = models.CharField(max_length=50)
tel = models.CharField(max_length=15, blank=True, null=True)
password = models.CharField(max_length=50, blank=True)
password2 = models.CharField(max_length=50, blank=True)

REQUIRED_FIELDS = ['role', 'email', 'tel']
REQUIRED_FIELDS = ['password', 'password2']

def __str__(self):
return self.username
22 changes: 10 additions & 12 deletions user/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@


class RegisterSerializer(serializers.ModelSerializer):
email = serializers.EmailField(
required=True,
validators=[UniqueValidator(queryset=User.objects.all())]
)
# email = serializers.EmailField(
# required=True,
# validators=[UniqueValidator(queryset=User.objects.all())]
# )
password = serializers.CharField(write_only=True, required=True, validators=[validate_password])
password2 = serializers.CharField(write_only=True, required=True)
role = serializers.CharField(required=True)
tel = serializers.CharField(required=False, allow_blank=True)
# role = serializers.CharField(required=True)
# tel = serializers.CharField(required=False, allow_blank=True)

class Meta:
model = User
fields = ('username', 'password', 'password2', 'email', 'role', 'tel')
fields = ('username', 'password', 'password2')
extra_kwargs = {
'username': {'required': True},
'email': {'required': True},
'role': {'required': True},
'password': {'required': True},
}

def validate(self, attrs):
Expand All @@ -31,11 +30,10 @@ def validate(self, attrs):
return attrs

def create(self, validated_data):
print(validated_data)
user = User.objects.create(
username=validated_data['username'],
email=validated_data['email'],
role=validated_data['role'],
tel=validated_data.get('tel', '')
password=validated_data['password'],
)

user.set_password(validated_data['password'])
Expand Down

0 comments on commit 1917f05

Please sign in to comment.