GSoC Update: [Check Constraints] New features and using it with Newforms.

9 views
Skip to first unread message

Thejaswi Puthraya

unread,
Jul 25, 2007, 10:06:49 PM7/25/07
to Django developers, bno...@gmail.com
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

Kenneth Gonsalves

unread,
Jul 25, 2007, 10:56:51 PM7/25/07
to django-d...@googlegroups.com

On 26-Jul-07, at 7:36 AM, Thejaswi Puthraya wrote:

> 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/


Jacob Kaplan-Moss

unread,
Jul 26, 2007, 12:12:38 PM7/26/07
to django-d...@googlegroups.com
On 7/25/07, Kenneth Gonsalves <law...@thenilgiris.com> wrote:
> On 26-Jul-07, at 7:36 AM, Thejaswi Puthraya wrote:
> > 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

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

Tom Tobin

unread,
Jul 26, 2007, 12:49:07 PM7/26/07
to django-d...@googlegroups.com

... and some of us bastards don't read -users at all. ^_^

Kenneth Gonsalves

unread,
Jul 26, 2007, 9:18:56 PM7/26/07
to django-d...@googlegroups.com

On 26-Jul-07, at 9:42 PM, Jacob Kaplan-Moss wrote:

>> 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.

Reply all
Reply to author
Forward
0 new messages