Changes between Version 1 and Version 2 of Ticket #26115


Ignore:
Timestamp:
Jan 21, 2016, 5:55:03 PM (9 years ago)
Author:
Tim Graham
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #26115 – Description

    v1 v2  
    1 In a data model that records changes over time to the way two entities relate, I am able to correctly display the latest record in an admin list by creating a callable using latest(). However, when sorting the column, if there is more than one record related to the admin list parent record, the number of rows will increase to that number, showing duplicates.
     1In a data model that records changes over time to the way two entities relate, I am able to correctly display the latest record in an admin list by creating a callable using `latest()`. However, when sorting the column, if there is more than one record related to the admin list parent record, the number of rows will increase to that number, showing duplicates.
    22
    3 An example is called for.
     3Example:
    44
    5 Given: A class Employee and a class Title, with a class EmployeeTitle that joins the two with start_date and end_date fields.
     5Given: A class `Employee` and a class `Title`, with a class `EmployeeTitle` that joins the two with `start_date` and `end_date` fields.
    66
    7 I'd like to show the employee's current title on the admin page, and be able to sort by that column. I create a callable current_title() in the Employee class which returns the latest of the employeetitle_set based on start_date.
     7I'd like to show the employee's current title on the admin page, and be able to sort by that column. I create a callable `current_title()` in the `Employee` class which returns the latest of the `employeetitle_set` based on `start_date`.
    88
    9 I set the admin order field to be 'employeetitle.title.name' (double underscores don't seem to work in this editor; I've substituted ".").
     9I set the admin order field to be `'employeetitle__title__name'`.
    1010
    11 If the employee has been more than one title the unsorted list displays correctly, but the list sorted by current_title shows duplicates where all the titles show the same current title.
     11If the employee has been more than one title the unsorted list displays correctly, but the list sorted by `current_title` shows duplicates where all the titles show the same current title.
    1212
    13 The expected behavior is that there is a single list entry for each employee and the list is sorted by the current_title.
     13The expected behavior is that there is a single list entry for each employee and the list is sorted by the `current_title`.
    1414
    1515I'm attaching a simple models.py and admin.py for reference.
Back to Top