On May 17, 12:07 am, Daniel Roseman <roseman.dan...@googlemail.com>
wrote:
> On May 16, 11:32 pm, ajohnsen <asdjohn...@gmail.com> wrote:
> > I am trying to assign max_value and min_value to a
> > PositiveIntegerField in my model but am getting the error:
>
> > year_built = models.PositiveIntegerField(min_value=1800,
> > max_value=2100)
> > TypeError: __init__() got an unexpected keyword argument 'max_value'
> <snip>
> > Can anyone explain to me what I am doing wrong and how I should be
> > assigning max and min values?
>
> It looks like you are confusing form and model fields. The forms
> version of IntegerField takes max_value and min_value parameters.
> However, models.IntegerField does not take these, hence your error.
>
> Unfortunately, until model validation is available, there's no way of
> enforcing this at the model level. You will need to define a modelform
> and override the definitino of year_built on the form.

I've been encountering the same problem. It's especially frustrating
because it seems model validation used to be much easier in Django
(see 
http://www.cotellese.net/2007/12/11/adding-model-field-validation-to-the-django-admin-page/
).

ajohnsen, you might want to see the Q&A I started over at Stack
Overflow recently:
http://stackoverflow.com/questions/849142/how-to-limit-the-maximum-value-of-a-numeric-field-in-a-django-model

Can anyone explain to me why model validation has been cut down so
arbitrarily? I mean, it's odd that one can specify *some* aspects of
what counts as valid for a particular field of a model (for instance:
how many decimal places a number can have; whether a number can be
negative; the maximum length of a character field; etc) but not others
(e.g. the maximum value of a number field).

Are the Django devs working to re-create model validation in a way
that would bring this missing functionality back to Django, or do they
think that people really ought to be breaking DRY by having to put
this stuff in every form that references a model for which you have
custom (though not uncommon) validation requirements? Or is there some
other way to do this that is better than both the aforementioned
options?

Thanks in advance for your help!

Sam

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to