I have a problem: I need to create a table in an admin page that summary data from others model but it's not an actual real model in the database.
How to implement this?
I have a problem: I need to create a table in an admin page that summary data from others model but it's not an actual real model in the database.
How to implement this?
I am assuming you are going to use existing models to calculate summery. Create instance methods/ properties in your model(as this will help to calculate your row level summery on models). For admin side you can use ModelAdmin with your Model (Probably a proxy model) and then blocki the actions.
Model instance method/property will used to calculate row level summery
class YourMainModel(models.Model):
# Your Model code
def instanceMethod(self)
return some_summery_calculation_based_on_model_fields
@property
def instanceProperty(self)
return some_summery_calculation_based_on_model_fields
class YourMainModelProxy(YourMainModel)
class Meta:
proxy=True
Now in admin.py
class YourSummeryModelAdmin(admin.ModelAdmin):
#Configure your model admin (Somewhat like this)
model = YourMainModelProxy
list_display = ['instanceMethod','instanceProperty'...]
# Disable add permission
def has_add_permission(self, request):
return False
# Disable delete permission
def has_delete_permission(self, request, obj=None):
return False
I hope this will be help.