Django Connect Temporary Pre_save Signal
I've been struggling with a Django signal issue for a few days now and would appreciate your thoughts. Scenario: I wish to use a black box method (it's actually the LayerMapping lo
Solution 1:
If I understood your question correctly, you can define the default value for the third field in your model
classMyModel(models.Model):
field1 = models.IntegerField()
field2 = models.IntegerField()
field3 = models.IntegerField(default=1) # This one is the problem
So if the value is not specified then Django will take 1 as default
Solution 2:
Django signals are mostly used as a hook point. Say you are writing a third party app which will be used by other people and you want to provide them with some hook points to manipulate your code, then signals would be used.
In your scenario, I would rather override the save()
method of Model than use a signal.
classMyModel(models.Model):
field1 = models.IntegerField()
///
field3 = models.IntegerField()
defsave(self, *args, **kwargs):
self.field3 = 1super(MyModel, self).save(*args, **kwargs)
Post a Comment for "Django Connect Temporary Pre_save Signal"