Automatic Generation of Models from File Data

2 views
Skip to first unread message

Collin Anderson

unread,
Apr 5, 2008, 12:13:59 AM4/5/08
to django-gsoc
# Automatic Generation of Models from File Data

The goal is to make a robust inspectfile command that would generate a
model from a data file, similar to inspectdb, but more powerful.

In a database-driven environments, developers often receive data in a
file to display on their website. During that process, they must
create the models for the data before they can import the data. I want
to make that step require very little effort from the developer.

### The inspectfile command would determine three things:
* File format: Is the file csv, json, xml, etc.
* File stucture: Is the data in a simple table, or is does it have a
nested structure that will lead to more than one model.
* Field types: Is a field an email address, phone number, url, etc.

#### File format: Is the file csv, json, xml, etc.
This can be determined by running parsers on the data until one comes
up with no errors.

#### File stucture: Is the data in a simple table, or is does it have
a nested structure that will lead to more than one model.
For csv, it will be a simple table. For xml and json, information can
be more dense.
This might end up being the hardest part. I would like to make it
handle many different structures.

#### Field types: Is a field an email address, phone number, url, etc.
This can be determined by running field validators on every row in the
column, and if none of the rows in the column have an error, it fits
that field type. The more specific fields must be tested first, with
TextField being the last resort.

* The program would be designed with a plugin architecture to allow
more file formats and structures.

### Additional Ideas, if there is time
#### Models from html files
inspectfile would look for table tags and display:table in an html
file and attempt to generate a model.

#### Generating code to import the data once the model is created.
inspectfile would generate code, in addition to the model to aid in
importing the data from the file to the database.

Kindly Requesting Comments,
Collin Anderson
Reply all
Reply to author
Forward
0 new messages