Skip to content Skip to sidebar Skip to footer

Subtract Two Fields From Django Admin

How do i subtract the two field values from django admin. here i gave my views and templtaes views.py for attendancesheet_info in attendance_sheet: attendancesheet_info.present_da

Solution 1:

You can calculate it in a class method in the model and reference that method in the admin as a read-only field in an edit view or list view in admin.py.

# this method goes into your model.@propertydefpresent_days(self):
    returnself.working_days - self.leave_days

Your example template will also work. You don't need to do anything in the view to access present_days. The code in your question from views.py is not needed.

<td>{{ attendancesheet_info.present_days}}</td>

Solution 2:

Assuming you have a model like AttendanceSheet defined in your models.py, you can create a ModelAdmin for this model in admin.py and specify the fields you want to appear on the admin page.

See the official documentation related to this topic, especially the exclude option.

Post a Comment for "Subtract Two Fields From Django Admin"