Assign field from related model as default in another model
<p>How can i assign the default value of current_amount as minimum_price?</p>

<pre><code>class Auction(models.Model):
    minimum_price = models.PositiveIntegerField()
    .....

class Bid(models.Model):
    product = models.ForeignKey(Auction, related_name='auction')
    # i want to set this field's default to value of minimum_price from Auction model
    current_amount = models.PositiveIntegerField(default=product__minimum_price)
    #also tried default=product.minimum_price
</code></pre>

<p>How can i achieve this? </p>

<p>One solution is </p>

<pre><code>class Bid(models.Model):
    product = models.ForeignKey(Auction, related_name='auction')
    current_amount = models.PositiveIntegerField()

    def save(self, *args, **kwargs):
        if not self.current_amount:
            self.current_amount = self.product.minimum_price
        super(Bid, self).save(*args, **kwargs)
</code></pre>

python django database sqlite django-models