prototype for transfer account
This commit is contained in:
parent
5043462095
commit
9e6d01b1bd
24
apps/account/transfer_data.py
Normal file
24
apps/account/transfer_data.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
from django.db.models import Value, IntegerField, F
|
||||||
|
from pprint import pprint
|
||||||
|
from transfer.models import Profiles, Accounts
|
||||||
|
from transfer.serializers.account import UserSerializer
|
||||||
|
|
||||||
|
|
||||||
|
def transfer_user():
|
||||||
|
# queryset = Profiles.objects.all()
|
||||||
|
# queryset = queryset.annotate(nickname=F("account__nickname"))
|
||||||
|
# queryset = queryset.annotate(email=F("account__email"))
|
||||||
|
|
||||||
|
queryset = Accounts.objects.filter(confirmed_at__isnull=False)
|
||||||
|
|
||||||
|
serialized_data = UserSerializer(data=list(queryset.values()), many=True)
|
||||||
|
|
||||||
|
if serialized_data.is_valid():
|
||||||
|
serialized_data.save()
|
||||||
|
else:
|
||||||
|
pprint(f"News serializer errors: {serialized_data.errors}")
|
||||||
|
|
||||||
|
|
||||||
|
data_types = {
|
||||||
|
"account": [transfer_user]
|
||||||
|
}
|
||||||
|
|
@ -10,7 +10,8 @@ class Command(BaseCommand):
|
||||||
"""
|
"""
|
||||||
DATA_TYPES = [
|
DATA_TYPES = [
|
||||||
'dictionaries',
|
'dictionaries',
|
||||||
'news'
|
'news',
|
||||||
|
'account'
|
||||||
]
|
]
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|
|
||||||
33
apps/transfer/serializers/account.py
Normal file
33
apps/transfer/serializers/account.py
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
from account.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class UserSerializer(serializers.ModelSerializer):
|
||||||
|
nickname = serializers.CharField()
|
||||||
|
email = serializers.CharField()
|
||||||
|
confirmed_at = serializers.DateTimeField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
|
||||||
|
fields = (
|
||||||
|
"nickname",
|
||||||
|
"email",
|
||||||
|
"confirmed_at"
|
||||||
|
)
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
data["username"] = self.get_username(data)
|
||||||
|
data["email_confirmed"] = self.get_email_confirmed(data)
|
||||||
|
data.pop("nickname")
|
||||||
|
data.pop("confirmed_at")
|
||||||
|
return data
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
User.objects.create(**validated_data)
|
||||||
|
|
||||||
|
def get_email_confirmed(self, obj):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_username(self, obj):
|
||||||
|
return obj["nickname"]
|
||||||
Loading…
Reference in New Issue
Block a user