Answer the question
In order to leave comments, you need to log in
How to get the field of the linked table?
There are a number of tables:
class UsedMoneyModel(models.Model):
name = models.CharField(max_length=10, unique=True, verbose_name='Название валюты')
class MoneyTypeModel(models.Model):
type = models.CharField(max_length=20, verbose_name='Тип платёжки')
class PaySystemModel(models.Model):
type = models.ForeignKey(MoneyTypeModel, on_delete=models.CASCADE, verbose_name='Тип') # Тип платёжки
base = models.ForeignKey(UsedMoneyModel, on_delete=models.SET_NULL, verbose_name='База',
null=True) # Базовая валюта
class ChangeModel(models.Model):
pay_from = models.ForeignKey(PaySystemModel, on_delete=models.CASCADE, verbose_name='Клиент отдаёт',
related_name='pay_from_change')
for i in ChangeModel.objects.all():
print(i.pay_from.base) - этот принт выводит None
print(i.pay_from.type) - этот принт отлично всё выводит
Answer the question
In order to leave comments, you need to log in
type is a reserved name in Python, change the field names and make sure the field actually stores something.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question