rrs: admin: add in-line for Milestones to Releases

If you're creating a new release then you will need to create milestones
within it, so add in-line forms for these. Unfortunately there's no
capability yet to automatically split up the release into n milestones
(or perhaps copy milestones from a previous release), that will have to
wait until later - for now this makes things a little easier.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-09-05 23:38:10 +12:00
parent b34d5072d7
commit da81a2cdf3

View File

@ -121,10 +121,29 @@ class MaintenancePlanAdmin(admin.ModelAdmin):
milestone.end_date = release.end_date
milestone.save()
class MilestoneFormSet(BaseInlineFormSet):
def clean(self):
super(MilestoneFormSet, self).clean()
total = 0
for form in self.forms:
if not form.is_valid():
return
if form.cleaned_data and not form.cleaned_data.get('DELETE'):
total += 1
if not total:
raise ValidationError('Releases must have at least one milestone')
class MilestoneInline(admin.StackedInline):
model = Milestone
formset = MilestoneFormSet
class ReleaseAdmin(admin.ModelAdmin):
search_fields = ['name']
list_filter = ['plan']
model = Release
inlines = [
MilestoneInline,
]
class MilestoneAdmin(admin.ModelAdmin):
search_fields = ['name']