U
U
uvv992021-12-08 12:56:28
Python
uvv99, 2021-12-08 12:56:28

How to write an agreement to send email notifications (django)?

Good afternoon.
Created a simple user account. Added to it: upload photo and gender selection (male/female). I can’t figure out how to add correctly - Agreement for sending notifications to the mail, who can tell?

from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm

from .models import Profile


class UserRegisterForm(UserCreationForm):
    SEX_CHOICES = (
        ('m',u"мужской"),
        ('w',u"женский"),
    )
    email = forms.EmailField(
        label='Введите Email',
        required=True,
        widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Введите Email'})
    )
    username = forms.CharField(
        label='Введите логин',
        required=True,
        help_text='Нельзя вводить символы: @, /, _',
        widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Введите логин'})
    )
    password1 = forms.CharField(
        label='Введите пароль',
        required=True,
        help_text='Минимальный пароль 8 символов',
        widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': 'Введите пароль'})
    )
    password2 = forms.CharField(
        label='Подтвердите пароль',
        required=True,
        widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': 'Повторно введите пароль'})
    )
    sex = forms.ChoiceField(label=u'Пол', choices = SEX_CHOICES)

    class Meta:
        model = User
        fields = ['username', 'email', 'password1', 'password2']


class UserUpdateForm(forms.ModelForm):
    SEX_CHOICES = (
        ('m',u"мужской"),
        ('w',u"женский"),
    )
    email = forms.EmailField(
        label='Введите Email',
        required=True,
        widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Введите Email'})
    )
    username = forms.CharField(
        label='Введите логин',
        required=True,
        help_text='Нельзя вводить символы: @, /, _',
        widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Введите логин'})
    )
    sex = forms.ChoiceField(label=u'Пол', choices = SEX_CHOICES)
    
    class Meta:
        model = User
        fields = ['username', 'email', 'sex']


class ProfileImageForm(forms.ModelForm):
    img = forms.ImageField(
        label='Загрузить фото',
        required=False,
        widget=forms.FileInput
    )
    class Meta:
        model = Profile
        fields = ['img']

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rodion, 2021-12-08
@uvv99

Alternatively, add another BooleanField field on the User model called has_agree_to_receive_notifications and add this field to the fields list

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question