From 74e2d2479822a16bb5e4f28ffd62b97bcf3df2aa Mon Sep 17 00:00:00 2001 From: emile Date: Thu, 29 May 2025 12:44:25 +0300 Subject: [PATCH] new --- .../commands/create_v1_milestones.py | 31 +++++++++++++++++++ osinaweb/osinacore/models.py | 1 + 2 files changed, 32 insertions(+) create mode 100644 osinaweb/osinacore/management/commands/create_v1_milestones.py diff --git a/osinaweb/osinacore/management/commands/create_v1_milestones.py b/osinaweb/osinacore/management/commands/create_v1_milestones.py new file mode 100644 index 00000000..32fa4a15 --- /dev/null +++ b/osinaweb/osinacore/management/commands/create_v1_milestones.py @@ -0,0 +1,31 @@ +# your_app/management/commands/create_v1_milestones.py + +from django.core.management.base import BaseCommand +from django.utils import timezone +from osinacore.models import Project, Milestone +from django.db.models import Count + + +class Command(BaseCommand): + help = 'Create a v1 milestone for all projects without one' + + def handle(self, *args, **kwargs): + today = timezone.now().date() + + projects_without_any_milestone = Project.objects.annotate( + milestone_count=Count('milestone') + ).filter(milestone_count=0) + + created_count = 0 + for project in projects_without_any_milestone: + end_date = project.end_date or today + Milestone.objects.create( + name="v1", + description="Initial v1 milestone", + project=project, + start_date=project.start_date, + end_date=end_date + ) + created_count += 1 + + self.stdout.write(self.style.SUCCESS(f"Created v1 milestones for {created_count} projects.")) diff --git a/osinaweb/osinacore/models.py b/osinaweb/osinacore/models.py index eb5e8e29..2a646c10 100644 --- a/osinaweb/osinacore/models.py +++ b/osinaweb/osinacore/models.py @@ -342,6 +342,7 @@ class Task(models.Model): end_date = models.DateField(null=True) assigned_to = models.ForeignKey(StaffProfile, on_delete=models.CASCADE, null=True) userstory = models.ForeignKey(UserStory, on_delete=models.SET_NULL, null=True, blank=True) + milestone = models.ForeignKey(Milestone, on_delete=models.SET_NULL, null=True, blank=True) task_id = models.CharField(max_length=20, null=True, blank=True) def save(self, *args, **kwargs): if not self.task_id: