[Answer]-How to customize the list data view in Django admin interface?

1👍

You have to build your own view and add it to admin.
Maybe the admin list_view is a good starting point.

If this sounds too much of work, I could imagine three work arounds:

  1. Make a new column for each task and each deadline and add the tasks and dealines there like “task_taskname” etc. Of course, this will be too much information if you are haveing mor then two or three tasks in each project.
  2. Reverse your logic! Don’t make a list_view for projects, but for tasks! You can still add the project name to this list. In fact, this is your current TaskAdmin.
  3. Generate the entrys for Task Name and Deadline using model functions. Additionally, give a short description like get_all_tasks.short_description = 'Task Name'. That should do the trick!

Funny enough, your question might have triggerd something in my brain and I made something very similar for my own project.
You can solve your problem by defining functions which provide your content (see my option 3. above):

class ProjectAdmin(admin.ModelAdmin):
    list_display = ('project_name', 'project_tasks', 'task_deadlines', 'end_date')
    list_filter = ['end_date']
    search_fields = ['project_name']

    def project_tasks(self, instance):
         out = ""
         for task in instance.task_set.all(): 
             #generate html output
             out += "{0}<br />".format(task.taskname)
         return out
    project_tasks.allow_tags = True #html should be renderd as is
    project_tasks.short_description = "Task Name"

    #Same for Deadline

That should do the trick!

this is how it looks like in my application

👤OBu

Leave a comment