Answer the question
In order to leave comments, you need to log in
How to populate a custom model in django when a new user is authenticated?
Good afternoon!
There is a model that implements the user profile. It is already filled with the data of different users, something like a phone directory. This model is related to User using one-to-one. Those. each user can have an entry in the directory. I bring part of the model.
class Person(models.Model):
user = models.OneToOneField(User, verbose_name='Пользователь', related_name='profile', blank=True, null=True, unique=True)
last_name = models.CharField(max_length=30, verbose_name='Фамилия')
first_name = models.CharField(max_length=30, verbose_name='Имя')
middle_name = models.CharField(max_length=30, verbose_name='Отчество')
birthday = models.DateField(verbose_name='Дата рождения', blank=True, default='00.00.0000')
email = models.EmailField(verbose_name='Email', blank=True)
photo = models.ImageField(upload_to=get_person_image_path, verbose_name='Фотография', blank=True, default=None)
class MySocialAccountAdapter(DefaultSocialAccountAdapter):
def pre_social_login(self, request, sociallogin):
email_domain = sociallogin.user.email.split('@')[1].lower()
if not email_domain == 'domain.tld':
raise ImmediateHttpResponse(HttpResponseRedirect('/forbidden/'))
else:
pass
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question