Create Form Fields, and Model fields to complement these Widgets

Issue #3 wontfix
Tom Grainger
created an issue

No description provided.

Comments (4)

  1. Gregor Müllegger repo owner

    I don't think that fits into the scope of django-rays. And there are not direct translations of those fields into a native SQL datatype, or is there one I don't know?

    I would prefer keeping these fields outside the project.

  2. Tom Grainger reporter

    They don't have a native SQL datatype per se, all they need to do is extend the relevant "real" datatype and add validation:


    class StepValidator():
    	def __init__(self, min_value, step):
    		self.min_value = min_value
    		self.step = step
    	def __call__(self, value):
    		if (value - self.min_value)% self.step != 0:
    			raise ValidationError(u'%s does not have the correct step' % value)
    class RangeField(m.IntegerField):
    	def __init__(self, min_value, max_value, step=None, *args, **kwargs):
    		validators = kwargs.setdefault("validators",[])
    		validators += [MinValueValidator(min_value), MaxValueValidator(max_value)]
    		if step:
    			validators.append(StepValidator(min_value, step))
    		super(RangeField, self).__init__(*args, **kwargs)
  3. Log in to comment