Combining two models to display on admin page?

I believe that is the term.

I have a 3 apps within a project. Inside one of the apps I have a models.py with two classes. class Client_Log and class Clients.
Client_Log has information such as control num, posted date and 11 other fields. Clients has last name, first name, DOD id number, and rank.

In the admin panel I have Clients set to display, L-Name, F-Name, MI, and DOD ID. In the Clients_Log I can only get the control num and posted date to show.
Ultimately, for the log I would like, control num, l-name, f-name and DOD ID to show. So I can easily search.

How is this achievable? I am not sure of the correct terms so when I search in google and I am not getting results I would like or that work.

Is there a ForeignKey between Client_Log and Clients? (If so, I’m assuming the ForeignKey field would be in Client_Log - referring to Clients.)

Are you referring to the listing page? (As opposed to the edit page of a particular Client_Log row.) If so, see all your options in the list_display docs.

I do have a foreignKey in my Client_Log referring to Clients.

Here is a screenshot of my clients (service members) and a snippet of the code from models.py
Imgur

class Clients(models.Model):

    class Meta:
        verbose_name_plural = "Service Members"
        verbose_name = "Service Members"

    last_name = models.CharField('Last Name', max_length=200, null=False, blank=False)

    first_name = models.CharField('First Name', max_length=200, null=False, blank=False)
    
    middle_initial = models.CharField('Middle Initial', max_length=1, blank=True)
    
    dod_id = models.CharField('DoD ID', max_length=10, null=False, blank=False, help_text="EXAMPLE: 1234567890")

    Grade_Rank = (
        ('E-1', 'E-1 - PVT'),
        ('E-2', 'E-2 - PV2'),

    )

    current_grade = models.CharField('Current Grade', max_length=4, choices=Grade_Rank, default='pvt', null=False)


    def __str__(self):
        return f"{self.last_name}, {self.first_name} {self.middle_initial} - - {self.dod_id}"

Here is one of my client_log and a snippet of the code from models.py
Imgur

class Client_Log(models.Model):

    class Meta:
        verbose_name_plural = "Leave Control Log"
        verbose_name = "Leave Control Log"

    clients = models.ForeignKey('Clients', on_delete=models.CASCADE, null=False, blank=False, verbose_name="Service Member")

    control_num = models.CharField('Control Number', unique=True, max_length=9, help_text="EXAMPLE: AD-1-0001 (Compnay Code-Last Digit FY-Sequence Number)", null=False, blank=False)

    corrected_entry = models.BooleanField('Corrected Entry?', default=False, help_text="SELECT IF YOU ARE CORRECTING THE LEAVE ENTRY")
    
    post_date = models.DateField('Date Posted', default=timezone.now, null=False, blank=False)

    def __str__(self):
        return f"{self.control_num}"

admin.py snippet

@admin.register(Client_Log)
class Client_Log(admin.ModelAdmin):
    search_fields = ('control_num', 'leave_code')
    list_display = ('control_num', 'post_date')


@admin.register(Clients)
class Clients(admin.ModelAdmin):
    search_fields = ('first_name', 'last_name', 'dod_id')
    list_display = ('last_name', 'first_name', 'middle_initial', 'dod_id')

What I am trying to a accomplish is have last_name, first_name and dod_id from Clients class to display them on the table in the second screenshot. Currently, if I add ‘last_name’ to list_display in Client_Log admin.py I get an error,

ERRORS:
<class 'clients.admin.Client_Log'>: (admin.E108) The value of 'list_display[1]' refers to 'Clients.last_name', 
which is not a callable, an attribute of 'Client_Log', or an attribute or method on 'clients.Client_Log'.

Let’s look at this error message.

It’s telling you that the entry in list_display must be

  • a callable (on Client_Log)
    • Clearly not since you don’t have a method in your Client_Log class named last_name
  • an attribute of Client_Log
    • Also clearly not true.

Note that those comments apply to both your Client_Log model class and the model admin class. (You probably should rename your model admin class to not create confusion between the model and the model admin classes.)

Your solution then is to provide one of these in your Client_Log class to expose that information to the ModelAdmin class.

See the examples in the list_display docs referenced above for some examples on how to resolve this.