Reputation: 70
class MyModel(models.Model):
maximum_limit = models.PositiveIntegerField(default=5)
Here I set maximum_limit default value is 5.
But I want to set a value which is also editable from admin and use here as a default value. (editable default value for model MyModel)
My initial approach is(not working). I want something like this.
class MySettings(models.Model):
mx_limit = models.PositiveIntegerField(default=5)
class MyModel(models.Model):
maximum_limit = models.PositiveIntegerField(default=MySettings.mx_limit)
Please help me
Upvotes: 0
Views: 659
Reputation: 22459
Your approach is wrong, a maximum for a db value should be set with the proper attribute, namely max_value.
However this would require a schemamigration everytime you want to change it. So what you really should be doing is dynamic form validation where your form checks for a setting (which should probably be saved in your database and not be statically stored in a module like Settings, which would require server restarts).
There are plenty examples how to make a form validation more dynamically on stackoverflow
Upvotes: 1