add a new method that counts the number of occurrences

This commit is contained in:
Fred Pauchet 2017-10-19 16:53:31 +02:00
parent ed59e72f68
commit 008e785154
2 changed files with 10 additions and 2 deletions

View File

@ -8,7 +8,7 @@ class InlineStandard(admin.StackedInline):
class ChapterAdmin(admin.ModelAdmin):
list_display = ('__str__', 'acronym')
list_display = ('__str__', 'acronym', 'number_of_associated_standards')
list_filter = ('section',)
inlines = [InlineStandard]

View File

@ -19,7 +19,15 @@ class Chapter(models.Model):
def __str__(self):
return '{} - {}'.format(self.acronym, self.name)
def number_of_associated_standards(self):
"""Returns the number of standards that are associated to the current chapter.
Returns:
An integer that counts the number of associated standards.
"""
return Standard.objects.filter(headline=self).count()
class Meta:
ordering = ('name',)