2012-07-07 11:14:04 +02:00
|
|
|
from django.db import models
|
|
|
|
|
2012-11-24 14:01:21 +01:00
|
|
|
|
2012-07-07 11:14:04 +02:00
|
|
|
class MinMaxIntegerField(models.IntegerField):
|
2013-09-25 12:53:44 +02:00
|
|
|
"""
|
|
|
|
IntegerField with options to set a min- and a max-value.
|
|
|
|
"""
|
|
|
|
|
2012-07-07 11:14:04 +02:00
|
|
|
def __init__(self, min_value=None, max_value=None, *args, **kwargs):
|
|
|
|
self.min_value, self.max_value = min_value, max_value
|
|
|
|
super(MinMaxIntegerField, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def formfield(self, **kwargs):
|
2012-11-24 14:01:21 +01:00
|
|
|
defaults = {'min_value': self.min_value, 'max_value': self.max_value}
|
2012-07-07 11:14:04 +02:00
|
|
|
defaults.update(kwargs)
|
|
|
|
return super(MinMaxIntegerField, self).formfield(**defaults)
|