-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.py
30 lines (24 loc) · 1.09 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from django import forms
from accounts.models import ProfileModel
from django.db import models
DJANGO_MODEL_TYPES = (models.CharField, models.TextField, models.DateField, models.URLField,
models.EmailField, models.ImageField, models.FileField, models.IntegerField)
class BaseModelForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for field_name, field in self.fields.items():
model_field = self._meta.model._meta.get_field(field_name)
if isinstance(model_field, DJANGO_MODEL_TYPES) and model_field.blank:
field.required = False
class ProfileForm(BaseModelForm):
birthdate = forms.DateField(
widget=forms.DateInput(attrs={'type': 'date'}),
help_text="Select your birthdate"
)
profile_picture = forms.ImageField(
help_text="Upload your profile picture"
)
class Meta:
model = ProfileModel
fields = ['profile_picture', "full_name", 'email', 'address', 'linkedin',
'github', 'phone_number', 'profile_description']