1👍
If I understood your question correctly, you can define the default value for the third field in your model
class MyModel(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
0👍
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.
class MyModel(models.Model):
field1 = models.IntegerField()
///
field3 = models.IntegerField()
def save(self, *args, **kwargs):
self.field3 = 1
super(MyModel, self).save(*args, **kwargs)
- [Answer]-And again Django can't find template (TemplateDoesNotExist)
- [Answer]-How to render django form into html (not in template)
- [Answer]-How to use the same auth userprofile in multiple apps in Django 1.6
- [Answer]-List_display in admin behave nothing
- [Answer]-Include post data from a second form when submitting
Source:stackexchange.com