[Answer]-How to associate some value in model with ForeignKey?

1👍

class Product(models.Model):
    currencies = models.ManyToManyField('Currency', through='Pricing', blank=True, null=True)

class Currency(models.Model):
    name = models.CharField()
    sign = models.CharField()

class Pricing(models.Model):
    product = models.ForeignKey(Product)
    currency = models.ForeignKey(Currency)
    price = models.FloatField()

and then you can use something like

product = Product.objects.get(name='Cactus')
price = product.pricing_set.get(currency__name='USD')

Leave a comment