add a new method that counts the number of occurrences
This commit is contained in:
parent
ed59e72f68
commit
008e785154
|
@ -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]
|
||||
|
||||
|
|
|
@ -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',)
|
||||
|
||||
|
|
Loading…
Reference in New Issue