feat: Enhances mood management capabilities

Updates `value` field validation to ensure positive integers,
preventing non-positive mood values in the model.

Adds functionality for creating new moods through the UI by
introducing `MoodCreateView`, integrating it into URLs and
enhancing the mood list view with creation options.

These enhancements improve data integrity and user experience
in mood management.
This commit is contained in:
Kumi 2024-12-25 22:32:56 +01:00
parent c04232e39a
commit 205d15cb8c
Signed by: kumi
GPG key ID: ECBCC9082395383F
4 changed files with 30 additions and 1 deletions

View file

@ -0,0 +1,24 @@
# Generated by Django 5.0.6 on 2024-12-25 21:32
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("mood", "0002_activity_hidden"),
]
operations = [
migrations.AlterField(
model_name="mood",
name="value",
field=models.IntegerField(
validators=[
django.core.validators.MinValueValidator(1),
django.core.validators.MaxValueValidator(255),
]
),
),
]

View file

@ -17,7 +17,7 @@ class Mood(models.Model):
name = models.CharField(max_length=64)
icon = models.CharField(default="fas fa-star", max_length=64)
color = ColorField(default="#000000")
value = models.IntegerField(validators=[MinValueValidator(0), MaxValueValidator(255)])
value = models.IntegerField(validators=[MinValueValidator(1), MaxValueValidator(255)])
def __str__(self):
return self.name

View file

@ -10,6 +10,7 @@ from .views import (
ActivityDeleteView,
MoodListView,
MoodEditView,
MoodCreateView,
NotificationCreateView,
NotificationDeleteView,
NotificationEditView,
@ -45,6 +46,7 @@ urlpatterns = [
),
path("mood/", MoodListView.as_view(), name="mood_list"),
path("mood/<int:id>/edit/", MoodEditView.as_view(), name="mood_edit"),
path("mood/new/", MoodCreateView.as_view(), name="mood_create"),
path("notification/", NotificationListView.as_view(), name="notification_list"),
path(
"notification/<int:id>/edit/",

View file

@ -265,6 +265,9 @@ class MoodListView(LoginRequiredMixin, ListView):
context = super().get_context_data(**kwargs)
context["title"] = "Moods"
context["subtitle"] = "The different moods you have defined."
context["buttons"] = [
(reverse_lazy("mood:mood_create"), "Create Mood", "pen")
]
return context
def get_queryset(self):