fux
This commit is contained in:
18
core/apps/accounts/migrations/0004_user_tg_id.py
Normal file
18
core/apps/accounts/migrations/0004_user_tg_id.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.2 on 2025-09-10 17:49
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounts', '0003_like'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='tg_id',
|
||||||
|
field=models.CharField(blank=True, max_length=20, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -5,6 +5,6 @@ from core.apps.shared.models.base import BaseModel
|
|||||||
|
|
||||||
|
|
||||||
class User(AbstractUser, BaseModel):
|
class User(AbstractUser, BaseModel):
|
||||||
pass
|
tg_id = models.CharField(max_length=20, null=True, blank=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,10 +44,13 @@ class UserSerializer(serializers.ModelSerializer):
|
|||||||
class UserLoginSerializer(serializers.Serializer):
|
class UserLoginSerializer(serializers.Serializer):
|
||||||
username = serializers.CharField()
|
username = serializers.CharField()
|
||||||
password = serializers.CharField()
|
password = serializers.CharField()
|
||||||
|
tg_id = serializers.CharField()
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
user = User.objects.filter(username=data['username'], is_superuser=True).first()
|
user = User.objects.filter(username=data['username'], is_superuser=True).first()
|
||||||
if not user:
|
if not user:
|
||||||
raise serializers.ValidationError("User not found")
|
raise serializers.ValidationError("User not found")
|
||||||
|
user.tg_id = data['tg_id']
|
||||||
|
user.save()
|
||||||
data['user'] = user
|
data['user'] = user
|
||||||
return data
|
return data
|
||||||
Reference in New Issue
Block a user