0752d476e4
* Remove headers * Changed lineendings to linux style in AUTHORS and CHANGELOG
19 lines
597 B
Python
19 lines
597 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
from django.db import models
|
|
|
|
|
|
class MinMaxIntegerField(models.IntegerField):
|
|
"""
|
|
IntegerField with options to set a min- and a max-value.
|
|
"""
|
|
|
|
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):
|
|
defaults = {'min_value': self.min_value, 'max_value': self.max_value}
|
|
defaults.update(kwargs)
|
|
return super(MinMaxIntegerField, self).formfield(**defaults)
|