How Can I Define A Django Model's Field Default Value To Be Another Field Value?
In my model I have these two fields:
start_bid = models.IntegerField(default=0) max_bid = models.IntegerField(default="the start_bid value")
start_bid will be added by the user once through Django ModelForm. And the
max_bid may change and may not.
So I need the first value of 'max_bid' to be the
start_bid value entered by the user, then if it changes it will be updated.
In brief, I need the initial value of
max_bid to be equal to the
Overwrite save method on model.
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): if self._state.adding: self.max_bid = self.start_bid super().save(force_insert, force_update, using, update_fields)
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module