У меня есть эти две модели:
class Transaction(models.Model):
store = models.ForeignKey(Store, on_delete=models.DO_NOTHING)
user = models.ForeignKey(User, on_delete=models.DO_NOTHING)
amount = models.DecimalField(max_digits=9, decimal_places=2)
cc_type = models.CharField(max_length=3, choices=CC_TYPES)
cc_transaction_id = models.CharField(max_length=200)
trans_date = models.DateTimeField()
qty = models.IntegerField()
def __str__(self):
return F'{self.store.title} - {self.cc_transaction_id} - {self.amount}'
class Meta:
unique_together = ('cc_type', 'cc_transaction_id')
class Ticket(models.Model):
transaction = models.ForeignKey(Transaction, on_delete=models.DO_NOTHING)
amount = models.DecimalField(max_digits=9, decimal_places=2)
ticket_id = models.CharField(max_length=200, unique=True)
def __str__(self):
return F'{self.ticket_id} - {self.amount}'
и эти ModelAdmins:
@admin.register(Transaction)
class TransactionAdmin(admin.ModelAdmin):
list_display = ['amount', 'cc_type', 'cc_transaction_id', 'user', 'store']
list_display_links = ['amount']
search_fields = ['cc_transaction_id', 'store__title', 'user__username']
@admin.register(Ticket)
class TicketAdmin(admin.ModelAdmin):
list_display = ['ticket_id', 'amount', 'transaction__qty']
list_display_links = ['ticket_id']
search_fields = ['ticket_id', 'transaction__cc_transaction_id', 'transaction__user__username']
При попытке запустить сервер запуска появляется ошибка:
<class 'Sales.Stores.admin.TicketAdmin'>: (admin.E108) The value of 'list_display[2]' refers to 'transaction__qty', which is not a callable, an attribute of 'TicketAdmin', or an attribute or method on 'stores.Ticket'
Кажется, что list_search
разрешается нормально, а list_display
- нет. Я делаю нечто подобное в TransactionAdmin и все вроде бы нормально.