Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

256
Vistas
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 %}
over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda