rrs: releases should be unique by plan and name, not just name

I missed changing this constraint when adding the plan field. We want to
be able to have the same named release on another plan.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-04-09 16:36:13 +12:00
parent 183ba0f7eb
commit 1f037470fb
2 changed files with 34 additions and 3 deletions

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rrs', '0010_recipemaintenancelink'),
]
operations = [
migrations.AlterField(
model_name='release',
name='name',
field=models.CharField(max_length=100),
),
migrations.AlterUniqueTogether(
name='release',
unique_together=set([('plan', 'name')]),
),
]

View File

@ -47,10 +47,13 @@ class MaintenancePlanLayerBranch(models.Model):
class Release(models.Model):
plan = models.ForeignKey(MaintenancePlan)
name = models.CharField(max_length=100, unique=True)
name = models.CharField(max_length=100)
start_date = models.DateField(db_index=True)
end_date = models.DateField(db_index=True)
class Meta:
unique_together = ('plan', 'name',)
def get_default_milestone(self):
return self.milestone_set.last()
@ -69,8 +72,13 @@ class Release(models.Model):
def get_current(maintplan):
current = date.today()
current_release = Release.get_by_date(maintplan, current)
return current_release or Release.objects.filter(plan=maintplan).order_by('-end_date')[0]
if current_release:
return current_release
else:
plan_releases = Release.objects.filter(plan=maintplan).order_by('-end_date')
if plan_releases:
return plan_releases[0]
return None
def __str__(self):
return '%s' % (self.name)