moviewyrm/fedireads/forms.py

76 lines
1.9 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
2020-03-15 21:15:36 +00:00
fields = ['name', 'rating', 'content']
2020-01-29 09:05:27 +00:00
help_texts = {f: None for f in fields}
2020-03-15 21:15:36 +00:00
content = IntegerField(validators=[
2020-02-11 23:17:21 +00:00
MinValueValidator(0), MaxValueValidator(5)
])
2020-01-29 09:05:27 +00:00
labels = {
'name': 'Title',
'rating': 'Rating (out of 5)',
2020-03-15 21:15:36 +00:00
'content': 'Review',
2020-01-29 09:05:27 +00:00
}
2020-02-18 05:39:08 +00:00
class CommentForm(ModelForm):
2020-03-21 23:50:49 +00:00
class Meta:
model = models.Comment
fields = ['name', 'content']
help_texts = {f: None for f in fields}
labels = {
'name': 'Title',
'content': 'Comment',
}
class ReplyForm(ModelForm):
2020-02-18 05:39:08 +00:00
class Meta:
model = models.Status
fields = ['content']
help_texts = {f: None for f in fields}
labels = {'content': 'Comment'}
2020-01-29 09:05:27 +00:00
class EditUserForm(ModelForm):
class Meta:
model = models.User
fields = ['avatar', 'name', 'summary', 'manually_approves_followers']
2020-01-29 09:05:27 +00:00
help_texts = {f: None for f in fields}
2020-02-18 05:39:08 +00:00
2020-02-21 06:19:19 +00:00
class TagForm(ModelForm):
class Meta:
model = models.Tag
fields = ['name']
help_texts = {f: None for f in fields}
2020-02-21 06:19:19 +00:00
labels = {'name': 'Add a tag'}