Re: Check Constrains in Django

2009-10-13 Thread Matt Schinckel

On Oct 14, 9:57 am, Christophe Pettus  wrote:
> On Oct 13, 2009, at 4:46 PM, Geobase Isoscale wrote:
>
> > Do your mean that its not possible for Django to recognize  
> > postgreSQL defined Check constraints when data is entered in the Form?
>
> That's correct.  CHECK constraints on the PostgreSQL database are not  
> automatically enforced at the form level in Django.  You'll need to  
> check and enforce those separately in your Django code.

The database will always prevent data that breaks constraints being
committed, however.  My patch changes the validation process so that
it will test those constraints automatically, and alert you in the
manner expected (raising ValidationError, and in the admin, putting
those lovely red boxes around the field).

I also hook into the creation process, and create the constraints in
the table/column definition.  Otherwise, you would need to add in the
constraints afterwards.  This isn't that relevant if you are not using
the syncdb command, for instance.

As for how to patch your installation: I use a mercurial mirror of
django, which I patch against.  There is no reason you could not just
patch the installed version, by manually looking at the diffs in the
patch, and applying those to the relevant files.

I was going to extend the patch, but my use of check constraints at
this stage is limited to strictly simple cases (start < finish, for
instance).  You may be able to extend it, and I am happy to help test
them, but I haven't really looked at geodjango, so I don't know much
about it.

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



Re: Check Constrains in Django

2009-10-13 Thread Christophe Pettus


On Oct 13, 2009, at 4:46 PM, Geobase Isoscale wrote:
> Do your mean that its not possible for Django to recognize  
> postgreSQL defined Check constraints when data is entered in the Form?

That's correct.  CHECK constraints on the PostgreSQL database are not  
automatically enforced at the form level in Django.  You'll need to  
check and enforce those separately in your Django code.

--
-- Christophe Pettus
x...@thebuild.com


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



Re: Check Constrains in Django

2009-10-13 Thread Geobase Isoscale
Matt, I too prefer enforcing check constraints at database level ( database
and model)  as opposed to GUI(graphical user interface) i.e. (Forms). Do
your mean that its not possible for Django to recognize postgreSQL defined
Check constraints when data is entered in the Form?  (or what do u mean by
Django not having the ability to easily mark columns or tables with check
contraints ?) .
Do I have to change to SVN to utilize the patch you created ?
Can I extend the patch to cater for spatial data types supported by
Geodjango?


Many Thanks To All

Isoscale

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



Re: Check Constrains in Django

2009-10-13 Thread Matt Schinckel

On Oct 14, 12:55 am, Geobase Isoscale  wrote:
> Hi All,
>
> I'm working with PostgreSQL database.
> I wonder how Django handles Check Constraints both (range and value based).
> To ensure integrity of data in the database as postresql does.
>
> How are they implemented in models and views.
>

Django does not have the ability to add in check constraints into the
postgresql database for you from your models, nor does it have the
ability to easily mark columns or tables as having said constraints.

I did raise a ticket about this, and create a patch (which I am
using), but it is specific to postgresql, and limited to simple
constraints.

The usual way is to have the constraints applied in the forms, using
the clean_column() and clean() methods.  I prefer having them at both
the database and model level, however.

You can see the thread in django-developers (http://
groups.google.com.au/group/django-developers/browse_thread/thread/
38937992972c7808/ef9783182671b348?lnk=gst=check
+constraint#ef9783182671b348), and the ticket (http://
code.djangoproject.com/ticket/11964).

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



Re: Check Constrains in Django

2009-10-13 Thread Brian McKeever

Are you asking about the technical details of how it's done, or just
how to do it?

If the latter, django uses field and form level validation.
http://docs.djangoproject.com/en/dev/ref/models/fields/#field-options
http://docs.djangoproject.com/en/dev/ref/forms/fields/#ref-forms-fields



On Oct 13, 8:55 am, Geobase Isoscale  wrote:
> Hi All,
>
> I'm working with PostgreSQL database.
> I wonder how Django handles Check Constraints both (range and value based).
> To ensure integrity of data in the database as postresql does.
>
> How are they implemented in models and views.
>
> Please assist in this direction
>
> Many Thanks
>
> Isoscale
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---