I have a model with several fields. And I wanted to add another field in django-admin (list_display), where it is the sum of all fields.
Model's
class Model1(models.Model):
field1 = models.DecimalField(blank=True,null=True,decimal_places=2,max_digits=8)
field2 = models.DecimalField(blank=True,null=True,decimal_places=2,max_digits=8)
field3 = models.DecimalField(blank=True,null=True,decimal_places=2,max_digits=8)
field3 = models.DecimalField(blank=True,null=True,decimal_places=2,max_digits=8)
field4 = models.DecimalField(blank=True,null=True,decimal_places=2,max_digits=8)
def __str__(self):
return str(self.id)
Model's Admin
class Model1Admin(admin.ModelAdmin):
model = Model1
list_display = ('field1','field2',<!--Sum of (field1,field2,field3,field4,field5-->)
admin.site.register(Modell,Model1Admin)
i am using the last version of django.