So here is how to use 'like' and 'between' check constraints....
class Manufacturer(models.Model):
mfg_name = models.CharField(maxlength=50)
car_sale_start = models.DateField()
car_sale_end = models.DateField()
quantity_sold = models.IntegerField()
car_price = models.IntegerField()
class Meta:
constraints = (
("check_name",Check(mfg_name__like =
'Merc*')),
("check_date",Check(car_sale_start__between =
[date(2007,1,1),date(2008,1,1)])),
("check_end_date",Check(car_sale_end__gte = 'car_sale_start')),
("check_quantity",Check(quantity_sold__gte = 0)),
("check_price",Check(car_price__between = [1000,10000])),
)
In the 'like' check data '*' matches 0 or more characters whereas '+'
matches a single character. (might go for a change, replacing '+' for
a '.')
'between' expects a two-element list which give the bounds for the
field.
The output SQL is:
CREATE TABLE "appname_manufacturer" (
"id" serial NOT NULL PRIMARY KEY,
"mfg_name" varchar(50) NOT NULL,
"car_sale_start" date NOT NULL,
"car_sale_end" date NOT NULL,
"quantity_sold" integer NOT NULL,
"car_price" integer NOT NULL,
CONSTRAINT "check_name" CHECK ("mfg_name" like 'Merc%%'),
CONSTRAINT "check_date" CHECK ("car_sale_start" between date
'2007-01-01' AND date '2008-01-01'),
CONSTRAINT "check_end_date" CHECK ("car_sale_end" >=
car_sale_start),
CONSTRAINT "check_quantity" CHECK ("quantity_sold" >= 0),
CONSTRAINT "check_price" CHECK ("car_price" between 1000 AND
10000)
)
;
Here is a way of using Newforms and Django Check Constraints
http://thejuhyd.blogspot.com/2007/07/django-newforms-and-django-check.html
This week I will work on adding support for the datetime field and
decide on whether to support the upper and lower functions.
Cheers
Thejaswi Puthraya
> This week I worked on getting the 'like' and 'between' check
> conditions into the project and also writing a lot of doctests.
could you post this to the users list also - you may get a lot of
feedback from the user's point of view
--
regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/
Actually, I've deliberately asked the SoC students to post updates
here instead of django-users. I know all the core devs read both
groups, but we skim -users most more lightly than -dev, and these
updates need to be seen by developers. I'd rather not mix up the
distinction between -users and -dev.
Jacob
... and some of us bastards don't read -users at all. ^_^
>> could you post this to the users list also - you may get a lot of
>> feedback from the user's point of view
>
> Actually, I've deliberately asked the SoC students to post updates
> here instead of django-users. I know all the core devs read both
> groups, but we skim -users most more lightly than -dev, and these
> updates need to be seen by developers. I'd rather not mix up the
> distinction between -users and -dev.
i agree - these should be in -dev, I just felt that this particular
post would excite/interest users so asked if he could post it in -
users also.