Hello Django Developers,
This week I worked on getting the 'like' and 'between' check
conditions into the project and also writing a lot of doctests.
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---