django-rest-auth custom registration failed to save extra fields even after changing save() method -
i trying integrate user registration , login custom fields. using django-rest-auth. have added fields model , in modelserializer have inherited rest_auth.registration.serializers.registerserializer although registration process successful,but custom fields not getting saved.
models.py
from django.db import models phonenumber_field.modelfields import phonenumberfield class vendor(models.model): login_type = ( ('1', 'my_form'), ('2', 'facebook'), ('3', 'google'),) status = ( ('0', 'signed_up'), ('1', 'otp_verified'), ('2', 'activated'),) device_type_choices = ( ('1', 'android'), ('2', 'ios'),) phone = phonenumberfield(unique=true) device_token = models.charfield(max_length=250) device_type = models.charfield(max_length=1, choices=device_type_choices) login_type = models.charfield(max_length=1, choices=login_type) status = models.charfield(max_length=1, choices=status) created_on = models.datetimefield(auto_now_add=true)
serializers.py
from rest_auth.registration.serializers import registerserializer rest_framework import serializers allauth.account.adapter import get_adapter allauth.account.utils import setup_user_email .models import vendor class vendorregisterserializer(serializers.modelserializer, registerserializer): class meta: model = vendor exclude = ('username',) def get_cleaned_data(self): return { 'password1': self.validated_data.get('password1', ''), 'email': self.validated_data.get('email', ''), 'phone': self.validated_data.get('phone', ''), 'device_token': self.validated_data.get('device_token', ''), 'login_type': self.validated_data.get('login_type', ''), 'device_type': self.validated_data.get('device_type', ''), 'status': self.validated_data.get('status', '') } def save(self, request): adapter = get_adapter() user = adapter.new_user(request) self.cleaned_data = self.get_cleaned_data() adapter.save_user(request, user, self) setup_user_email(request, user, []) user.phone = self.cleaned_data.get('phone') user.device_token = self.cleaned_data.get('device_token') user.login_type = self.cleaned_data.get('login_type') user.device_token = self.cleaned_data.get('device_token') user.device_type = self.cleaned_data.get('device_type') user.status = self.cleaned_data.get('status') user.save() print(user.phone) return user
Comments
Post a Comment