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:
parent
c04232e39a
commit
205d15cb8c
4 changed files with 30 additions and 1 deletions
24
mood/migrations/0003_alter_mood_value.py
Normal file
24
mood/migrations/0003_alter_mood_value.py
Normal 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),
|
||||
]
|
||||
),
|
||||
),
|
||||
]
|
|
@ -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
|
||||
|
|
|
@ -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/",
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue