M
M
Malik2020-08-24 12:02:46
Django
Malik, 2020-08-24 12:02:46

I added my fields to the model User, I can’t display it in the user registration template, how to display it?

I added my fields to the model User, since the default fields are not enough for me,
how can I display the other three fields?

model.py:

class Profile(models.Model):
    user = models.OneToOneField(User, related_name='profile', on_delete=models.CASCADE,
                                verbose_name='Пользователь')
    avatar = models.ImageField(null=True, blank=True, upload_to='user_pics', verbose_name='Аватар')
    second_name = models.CharField(max_length=100, null=True, blank=True, verbose_name='Отчество')
    gender = models.CharField(max_length=20, verbose_name='Пол',
                              choices=GENDER_CHOICES, default=USER_GENDER_CHOICES)
    country = models.CharField(max_length=20, verbose_name='Страна',
                               choices=COUNTRY_CHOICES, default=USER_COUNTRY_CHOICES)

    def __str__(self):
        return self.user.get_full_name() + "'s Profile"

    class Meta:
        verbose_name = 'Профиль'
        verbose_name_plural = 'Профили'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2020-08-24
@baskserg


You need to extend the default UserCreationForm class and then store the values . You can see a detailed description of the process in the link

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question