-1

I want to create a model in Django with two fields {initial price, current price} .. is there a way in Django to set the default value for the current price field to be the same as the initial price field value?

1 Answers1

0

Not sure why you would have 2 price fields with one as initial and another.

But a possible workaround for that would be to override the save() method of the model to set the initial value for the model's current price.

e.g:

def save(self, *args, **kwargs):
    if not self.pk:
        self.current_price = self.initial_price
    super(Model, self).save(*args, **kwargs)

Of course the above is just an example and is not an exact/specific answer, but I think that's a good starting point.

iklinac
  • 14,944
  • 4
  • 28
  • 30
Jammeh
  • 63
  • 2
  • 16
  • I want to two different price variables because its an auction .. every listing has an initial price and every time someone adds a bid the current price will be updated – Muhammad Abd-Elsattar Sep 02 '20 at 12:58
  • @MuhammadAbd-Elsattar then overriding the save() is one of your best options here. – Jammeh Sep 02 '20 at 12:59