Reputation: 1454
I just got the requirement to show data on Django admin panel in a certain way. Actually I have log table in which I have userid and action it took.
class AuditTrail(models.Model):
id = models.AutoField(primary_key=True)
userid = models.ForeignKey('User', null=True, db_column='UserId')
action = models.CharField(max_length=200L, db_column='Action')
timestamp = models.DateTimeField(null=True, db_column='Timestamp', blank=True)
When I add it on the admin panel it just give me all the entries in AuditTrail table. I have created filters on timestamp, search on userid and default ordering. But what actually is needed is on the main page where all the entries are shown I need to group rows on userid. and on clicking userid I need to implement expand/collapse logic.
In short on the main page of the model I get list of all users and I can collapse and expand all the rows for that user. Can I achieve this somehow in django admin panel. Does django give the functionality of grouping model objects on some field? Thanks in advance.
Edit 1: If it is not achievable in Django? What i have done now is i have created a link for each user's audit trail and i created a custom field and added in User's table.
Upvotes: 3
Views: 3485
Reputation: 336
You need to customise the default template and add asset definitions.
For grouping you might need regroup builtin tag.
Upvotes: 3