fix: Transmit confidant_email on edit
This commit is contained in:
parent
6835240173
commit
a8464d7536
7 changed files with 89 additions and 14 deletions
20
userausfall/migrations/0004_user_confidant.py
Normal file
20
userausfall/migrations/0004_user_confidant.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 2.2.20 on 2021-05-18 08:09
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('userausfall', '0003_auto_20210414_0827'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='confidant',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
|
@ -68,6 +68,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
|||
),
|
||||
)
|
||||
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
|
||||
confidant = models.ForeignKey("User", on_delete=models.SET_NULL, null=True)
|
||||
|
||||
objects = UserManager()
|
||||
|
||||
|
@ -83,6 +84,9 @@ class User(AbstractBaseUser, PermissionsMixin):
|
|||
super().clean()
|
||||
self.email = self.__class__.objects.normalize_email(self.email)
|
||||
|
||||
def get_confidant_email(self):
|
||||
return ""
|
||||
|
||||
def get_full_name(self):
|
||||
"""
|
||||
Return the first_name plus the last_name, with a space in between.
|
||||
|
|
|
@ -7,9 +7,26 @@ from userausfall.models import AccountRequest
|
|||
class AccountRequestSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = AccountRequest
|
||||
fields = ('url', 'email', 'confidant_email', 'username', 'is_verified', 'is_trustable')
|
||||
fields = (
|
||||
"url",
|
||||
"email",
|
||||
"confidant_email",
|
||||
"username",
|
||||
"is_verified",
|
||||
"is_trustable",
|
||||
)
|
||||
|
||||
|
||||
class UserSerializer(BaseUserSerializer):
|
||||
confidant_email = serializers.EmailField(source="get_confidant_email")
|
||||
|
||||
class Meta(BaseUserSerializer.Meta):
|
||||
fields = ('email', 'username')
|
||||
fields = ("email", "username", "confidant_email")
|
||||
|
||||
def get_confidant_email(self):
|
||||
return ""
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
print(validated_data)
|
||||
confidant = validated_data.pop("get_confidant_email")
|
||||
return super().update(instance, validated_data)
|
||||
|
|
Reference in a new issue