new
parent
14cf38beb3
commit
74e2d24798
@ -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."))
|
Loading…
Reference in New Issue