From 1f1347b48b376dbea0a4439fb20d019024f99285 Mon Sep 17 00:00:00 2001
From: Ernesto Rico Schmidt <ernesto@helsinki.at>
Date: Tue, 14 Feb 2023 14:37:34 -0400
Subject: [PATCH] Add by_weekdays field and choices

- Add choices for freq
- Add choices for by_set_pos
- Add unique_together
---
 program/models.py | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/program/models.py b/program/models.py
index c163df7c..c05fc1cd 100644
--- a/program/models.py
+++ b/program/models.py
@@ -234,13 +234,42 @@ class ShowLink(Link):
 
 class RRule(models.Model):
     name = models.CharField(max_length=32, unique=True)
-    freq = models.IntegerField()
+    freq = models.IntegerField(
+        choices=[
+            (0, "once"),
+            (1, "monthly"),
+            (2, "weekly"),
+            (3, "daily"),
+        ]
+    )
     interval = models.IntegerField(default=1)
-    by_set_pos = models.IntegerField(blank=True, null=True)
+    by_set_pos = models.IntegerField(
+        blank=True,
+        choices=[
+            (1, "first"),
+            (2, "second"),
+            (3, "third"),
+            (4, "fourth"),
+            (5, "fifth"),
+            (-1, "last"),
+        ],
+        null=True,
+    )
+    by_weekdays = models.CharField(
+        blank=True,
+        choices=[
+            (None, ""),
+            ("0,1,2,3,4", "business days"),
+            ("5,6", "weekends"),
+        ],
+        null=True,
+        max_length=9,
+    )
     count = models.IntegerField(blank=True, null=True)
 
     class Meta:
         ordering = ("pk",)
+        unique_together = ("freq", "interval", "by_set_pos", "by_weekdays")
 
     def __str__(self):
         return self.name
-- 
GitLab