From c413c953e10cfe3e129d86a23e79ad5198dfcae0 Mon Sep 17 00:00:00 2001 From: pwhipp Date: Thu, 16 Oct 2014 11:10:34 +1000 Subject: [PATCH] Added subproject admin (#120) --- core/settings/includes/common.py | 1 + cvs/admin.py | 1 + projects/admin.py | 19 +++++++++++++++++-- projects/models.py | 7 ++++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/settings/includes/common.py b/core/settings/includes/common.py index 4d99770..047c8e5 100644 --- a/core/settings/includes/common.py +++ b/core/settings/includes/common.py @@ -235,6 +235,7 @@ ("Content", ("cvs.CV", "projects.Project", + "projects.SubProject", "pages.Page", "blog.BlogPost", "generic.ThreadedComment", diff --git a/cvs/admin.py b/cvs/admin.py index d5550cf..54ba714 100644 --- a/cvs/admin.py +++ b/cvs/admin.py @@ -13,6 +13,7 @@ class CVProjectInline(admin.StackedInline): model = cm.CVProject extra = 1 fields = ('project', + 'subproject', 'from_date', 'to_date', 'position', diff --git a/projects/admin.py b/projects/admin.py index 70b500b..cc62ed4 100644 --- a/projects/admin.py +++ b/projects/admin.py @@ -25,7 +25,8 @@ class CVProjectInline(admin.StackedInline): model = cm.CVProject exclude = ('cv',) readonly_fields = ('cv_link',) - fields = ('from_date', + fields = ('subproject', + 'from_date', 'to_date', 'position', 'activities', @@ -40,12 +41,18 @@ def cv_link(self, instance): return mark_safe(u'{name}'.format(u=instance.cv.admin_url, name=instance.cv.title)) +class SubProjectInline(admin.TabularInline): + extra = 1 + model = pm.SubProject + fields = ('name',) + + class ProjectAdmin(admin.ModelAdmin): list_display = ('name', 'from_date', 'to_date', 'locality', 'region') list_filter = ('countries', 'to_date') search_fields = ('title', 'region') filter_horizontal = ('countries', 'cccs_subthemes', 'cccs_subsectors', 'ifc_subthemes', 'ifc_sectors') - inlines = (CVProjectInline,) + inlines = (CVProjectInline, SubProjectInline) fieldsets = ((None, {'fields': ('title_en', 'title_fr', 'title_ru', @@ -194,3 +201,11 @@ class IFCSectorAdmin(HasProjectsAdmin): admin.site.register(pm.IFCSector, IFCSectorAdmin) + +class SubProjectAdmin(admin.ModelAdmin): + list_display = ('project', 'name') + list_filter = ('project',) + search_fields = ('project__name', 'name') + +admin.site.register(pm.SubProject, SubProjectAdmin) + diff --git a/projects/models.py b/projects/models.py index d604668..f82b129 100644 --- a/projects/models.py +++ b/projects/models.py @@ -216,4 +216,9 @@ class SubProject(models.Model): name = models.CharField(max_length=128) class Meta: - unique_together = ('project', 'name') \ No newline at end of file + unique_together = ('project', 'name') + verbose_name = 'Sub-project' + verbose_name_plural = 'Sub-projects' + + def __unicode__(self): + return u'{0}'.format(self.name) \ No newline at end of file