GSoC 2007: Implementing Check Constraints

2007-05-25 Thread theju

Hello everyone,
I am a participant in the Summer of Code 2007 and working on
"Implementing Check Constraints in Django". My mentor is Simon
Blanchard.

The hosting page for the projects is at 
http://code.google.com/p/django-check-constraints/
and the Proposed Features Wiki at 
http://code.google.com/p/django-check-constraints/wiki/Features

As you can see from the features page on the wiki, implementing check
constraints will actually reduce the need for writing validators (all
you require is to add the constraints in the models). Since the
constraints are being implemented at the database-level it provides
for better data integrity.

Lately, I have been studying Django's API and have realized that most
of the foundation is already present for me to work on( I would like
to thank Adrian, Jacob and all the developers of Django for this).

For my project,all that I have to do is actually append the sql
statements for the table (containing the check statements) when syncdb
is called. My problem is a typical one that "There is more than one
way of doing it"

Here's how I believe I might be able do it...
1) By creating a Check Field (that inherits the Field from
django.db.models.fields) and getting things done. So I might have to
make a few changes in the django.core.management [precisely in the
_get_sql_model_create function and not to forget the data_types]
2) As proposed by my mentor by getting it done from the
django.db.models.options file.

So which is the best method to go about this problem (even if one
doesn't exist in the list above, please suggest)?

Thanking You
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 django-developers@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Custom field _post_create_sql()

2007-05-30 Thread theju

Though I am not conversant with the details of the GIS fundas, here is
my observationtheir application gave a very good pointer to people
who always wanted to do custom field development. I wouldn't be happy
to see SQL statements be used in the class (even though it gets the
work because I believe there is another place for it in the
management.py or the data_types).

Here is what I did (not complete as yet):

Created a Check class which inherits the Field Class and write all the
attributes or methods here.
Next, in the management.py I make small changes and write the
appropriate SQL statements.

In management.py 
In _get_sql_model_create(),
...
for f in opts.fields:
if isinstance(f, (models.ForeignKey, models.OneToOneField)):
rel_field = f.rel.get_related_field()
while isinstance(rel_field, (models.ForeignKey,
models.OneToOneField)):
rel_field = rel_field.rel.get_related_field()
data_type = get_rel_data_type(rel_field)
elif isinstance(f,Check):
# Write my SQL statements here.
else:
rel_field = f
data_type = f.get_internal_type()
col_type = data_types[data_type]
if col_type is not None:
# Make the definition (e.g. 'foo VARCHAR(30)') for this
field.
field_output =
[style.SQL_FIELD(backend.quote_name(f.column)),
style.SQL_COLTYPE(col_type % rel_field.__dict__)]
field_output.append(style.SQL_KEYWORD('%sNULL' % (not
f.null and 'NOT ' or '')))
...
Personally, I believe not all cases for custom SQL development require
SQL to be appended (like mine), so is there a necessity for
_post_create_sql() for my project???


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
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
-~--~~~~--~~--~--~---