kumify/common/fields.py
Klaus-Uwe Mitterer 893c13a0b4 Prepare models for habits
Add fields for weekdays and days of month
Update requirements to include dateutil, polymorphic, multiselectfield
2021-01-08 18:32:25 +01:00

24 lines
No EOL
830 B
Python

from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator, validate_comma_separated_integer_list
from multiselectfield import MultiSelectField
class WeekdayChoices(models.IntegerChoices):
MONDAY = 0, "Monday"
TUESDAY = 1, "Tuesday"
WEDNESDAY = 2, "Wednesday"
THURSDAY = 3, "Thursday"
FRIDAY = 4, "Friday"
SATURDAY = 5, "Saturday"
SUNDAY = 6, "Sunday"
class PercentageField(models.FloatField):
default_validators = [MaxValueValidator(100), MinValueValidator(0)]
class WeekdayField(MultiSelectField):
def __init__(self, *args, **kwargs):
self.choices = WeekdayChoices.choices
super().__init__(*args, **kwargs)
class DayOfMonthField(models.PositiveIntegerField):
default_validators = [MinValueValidator(1), MaxValueValidator(31)]