My goal is to automatically set a default value for a field in Django based on the selection of another field. In this case, the field that needs the default value is linked to a foreign key.
class Product(models.Model):
description = models.CharField('Description', max_length=200)
price = models.FloatField('Price')
class Sell(models.Model):
product = models.ForeignKey(Product)
price = models.FloatField('Price')
Each "Product" has a default price or suggested price stored in the database. When a user wants to add a new sell entry in the Admin pages and selects a specific product, I need to dynamically copy the suggested price from the corresponding Product entry to the Sell entry's price field. However, I can't depend on the standard save method as the user might make changes during the process.
Is there an elegant way within Django to achieve this functionality without explicitly resorting to JavaScript?