Answer the question
In order to leave comments, you need to log in
Two ForeignKeys in the model, how to implement?
I have a currency model:
class Currencies(models.Model):
name = models.CharField(verbose_name='Название', max_length=3, unique=True)
class Rates(models.Model):
class Meta:
# делает уникальным направление обмена
unique_together = ("_from", "_to")
# эталон
_from = models.ForeignKey(Currencies, verbose_name='Эталон')
# валюта
_to = models.ForeignKey(Currencies, verbose_name='Валюта')
rate = models.FloatField(verbose_name='Курс')
ERRORS:
currencies.Rates._from: (fields.E304) Reverse accessor for 'Rates._from' clashes with reverse accessor for 'Rates._to'.
HINT: Add or change a related_name argument to the definition for 'Rates._from' or 'Rates._to'.
currencies.Rates._to: (fields.E304) Reverse accessor for 'Rates._to' clashes with reverse accessor for 'Rates._from'.
HINT: Add or change a related_name argument to the definition for 'Rates._to' or 'Rates._from'.
Answer the question
In order to leave comments, you need to log in
class Rates(models.Model):
class Meta:
# делает уникальным направление обмена
unique_together = ("_from", "_to")
# эталон
_from = models.ForeignKey(Currencies, verbose_name='Эталон', related_name="rates_from")
# валюта
_to = models.ForeignKey(Currencies, verbose_name='Валюта', related_name="rates_to")
rate = models.FloatField(verbose_name='Курс')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question