bookwyrm/fedireads/forms.py

48 lines
1.3 KiB
Python
Raw Normal View History

2020-01-29 09:05:27 +00:00
''' usin django model forms '''
2020-02-11 23:17:21 +00:00
from django.core.validators import MaxValueValidator, MinValueValidator
from django.forms import ModelForm, PasswordInput, IntegerField
2020-01-29 09:05:27 +00:00
from fedireads import models
class LoginForm(ModelForm):
class Meta:
model = models.User
fields = ['username', 'password']
help_texts = {f: None for f in fields}
widgets = {
'password': PasswordInput(),
}
class RegisterForm(ModelForm):
class Meta:
model = models.User
fields = ['username', 'email', 'password']
help_texts = {f: None for f in fields}
widgets = {
'password': PasswordInput(),
}
class ReviewForm(ModelForm):
class Meta:
model = models.Review
fields = ['name', 'review_content', 'rating']
help_texts = {f: None for f in fields}
2020-02-11 23:17:21 +00:00
review_content = IntegerField(validators=[
MinValueValidator(0), MaxValueValidator(5)
])
2020-01-29 09:05:27 +00:00
labels = {
'name': 'Title',
'review_content': 'Review',
'rating': 'Rating (out of 5)',
}
class EditUserForm(ModelForm):
class Meta:
model = models.User
fields = ['avatar', 'name', 'summary']
help_texts = {f: None for f in fields}