Неподдерживаемый lookup 'phone_number' для ForeignKey или join по полю не разрешен в многотабличных унаследованных моделях django

У меня есть 2 модели, BaseTransaction и AccountTransaction. Каждая из них является отдельной моделью. Но я создал модель AcccountTransaction, наследуя BaseTransaction. В каждой из них есть таблицы. Проблема в том, что когда я добавляю любое поле BaseTransaction в AccountTransaction admin и пытаюсь выполнить поиск, то выдается ошибка, приведенная ниже в заголовке.

class BaseTransaction(mixins.DeviceForTransactionMixin):
    """
    Base class for transactions.
    """
    # Choices: Debit (income) or Credit (expense)
    # NOTE: Income means the transactions to wallet
    transaction_type = models.CharField(
        choices=choices.TransactionType.choices,
        max_length=6,
        default=choices.TransactionType.CREDIT,
        db_index=True,
    )
    # Choices: Auto or Manual
    # Auto: Automatically transfer the money to the GasMeter by cron job
    # Manual: Manually transfer the money to the GasMeter by user
    transfer_type = models.CharField(
        choices=choices.TransferType.choices,
        max_length=6,
        default=choices.TransferType.MANUAL,
        db_index=True,
    )
    # Choices: Pending, On hold, Success, Failed, Canceled
    # Pending: The transaction is pending (on created)
    # On hold: The transaction is on hold (on hold)
    # Success: The transaction is successful (success)
    # Failed: The transaction is failed (failed)
    # Canceled: The transaction is canceled (canceled)
    status = models.CharField(
        choices=choices.TransactionStatus.choices,
        max_length=8,
        default=choices.TransactionStatus.PENDING,
        db_index=True,
    )
    # To find out where the money came from
    # Choices: Card, Wallet
    source = models.CharField(
        choices=choices.TransactionSource.choices,
        max_length=8,
        db_index=True,
    )
    # To find out where the money went
    # Choices: Wallet, Account, Service, Gas cylinder, Loan
    receiver = models.CharField(
        choices=choices.TransactionReceivers.choices,
        max_length=16,
        db_index=True,
    )

    user = models.ForeignKey(
        to=get_user_model(),
        on_delete=models.PROTECT,
        related_name="transactions",
        verbose_name=_("User"),
        db_index=True,
    )

    card: UserCard = models.ForeignKey(
        to="payments.UserCard",
        related_name="transactions",
        on_delete=models.PROTECT,
        verbose_name=_("Card"),
        db_index=True,
    )

    amount = models.DecimalField(
        max_digits=10,
        decimal_places=2,
        verbose_name=_("Amount"),
    )

    # Transaction succeed time
    transferred_at = models.DateTimeField(
        verbose_name=_("Transferred at"),
        null=True,
        blank=True,
        db_index=True,
    )
    created_at = models.DateTimeField(
        auto_now_add=True,
        verbose_name=_("Created at"),
        db_index=True,
    )
    updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated at"))

    objects = managers.BaseTransactionManager()

    class Meta:
        verbose_name = _("All transactions")
        verbose_name_plural = _("All transactions")
class AccountTransaction(BaseTransaction):
    """
    All transactions related to wallets. Send or receive.
    """
    wallet: UserCard = models.ForeignKey(
        to="payments.UserCard",
        related_name="wallet_transactions",
        on_delete=models.PROTECT,
        verbose_name=_("Wallet"),
        db_index=True,
    )
@admin.register(AccountTransaction)
class AccountTransactionAdmin(DecimalFormatMixin, admin.ModelAdmin):
    list_display = ("id", "get_card", "transferred_at", "get_transfer_type",
                    "amount", "get_status", "receiver", "get_transferred_to")
    list_filter = ("transfer_type", "status", "receiver", "source", "created_at")
    search_fields = ("user__phone_number", "gas_meter", )
    decimal_format_fields = ("amount", )
    readonly_fields = ("created_at", "updated_at",)

Вот мои модели и настройки администратора

Вернуться на верх