Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
Django - add summary table in admin-site

What I want to achieve is to have a list of associations on one column and total members on the other column, like so:

enter image description here

I have tried to look for other solutions here with no luck, is there something i'm missing?

Still a newbie so appreciate all your help and guidance, folks!


models.py

class Member(models.Model):
   member_no = models.AutoField(primary_key=True)
   association = models.ForeignKey('Association')
   ...


class Association(models.Model):
   asoc_name = models.CharField(max_length=50, null=True, blank=True)

   class Meta:
      db_table = 'Association'

    def __str__(self):
       return self.asoc_name

    def __unicode__(self):
       return self.asoc_name


 class AssociationSummary(Association):
    class Meta:
       proxy = True
       verbose_name = 'Association Summary'
       verbose_name_plural = 'Association Summary'

admin.py

@admin.register(AssociationSummary)
class ChartAssociationAdmin(admin.ModelAdmin):
   change_list_template = 'admin/chart_association.html'


   def get_total(self):
       total = Member.objects.all().aggregate(association=Sum('member_no'))
       return total

   def changelist_view(self, request, extra_context=None):
       my_context = {
           'member_no': self.get_total(),
       }
       return super(ChartAssociationAdmin, self).changelist_view(request,
                                                     extra_context=my_context)

chart_association.html

{% extends 'admin/change_list.html' %}

{% block content_title %}
   <h1> Association Summary </h1>
{% endblock %}

{% block result_list %}
<div class=”results”>
<table>

<thead>
  <tr>
    <th>
      <div class=”text”>
        <span>Association</span>
      </div>
    </th>
    <th>
      <div class=”text”>
        <span>Total Members</span>
      </div>
    </th>
  </tr>
</thead>
<tbody>
  {% for row in member %}
  <tr class="{% cycle 'row1' 'row2' %}">
    <td> {{ row.asoc_name }} </td>
    <td> {{ row.total }} </td>
  </tr>
  {% endfor %}
</tbody>

</table>
</div>


{% endblock %}

{% block pagination %}{% endblock %}
about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!