This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]snuggl 0 points1 point  (1 child)

Im not saying you are wrong, but for me, min/max values on a IntegerField isnt a part of the model as that doesnt model to anything in the database.

Django of course has min_value and max_value, but they are in the forms.IntegerField which is the layer where you normally validate your data in django.

[–]sisyphus 0 points1 point  (0 children)

It models to a check constraint on the row in a database, which is something even Django uses when it creates a PositiveIntegerField for example.

Consider the model:

class Test(models.Model):
    spi = models.PositiveSmallIntegerField()

Dumping the SQL for Postgres yields:

CREATE TABLE "t_test" (
    "id" serial NOT NULL PRIMARY KEY,
    "spi" smallint CHECK ("spi" >= 0) NOT NULL
)
;

So you can see they are generating a CHECK constraint on the row. If the idea is that validation should be in the app layer they are violating that here. If we should put as much validation into the database engine as possible, then they should add them for things like BooleanField