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
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
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'.