Hi Greg
What you'll need to is create a project (django-admin.py startproject I
think). Then create an app inside that project (./manage.py startapp). Once
you have the project and app directory structure edit the settings.py file
to put it your database settings. After that's done you should be able to
run:

    ./manage.py inspectdb > app_directory/models.py

The models.py file will now reflect the structure of your database (i.e. it
will have created all of the models for you). You will just need to go
through it and edit any fields which are ForeignKeys, and any which are
primary keys (add primary_key=True). You'll probably want to tidy up the
reverse relation names too (I don't like having "<model>_set" so I usually
override this with related_name="whatever"). ManyToMany will be a bit more
complicated... assuming that there are no extra fields in your many to many
table then you could add "db_table=<whatever>" to the ManyToMany field
declaration and delete the Model that inspectdb will have created for you.
Or you could leave it in your models.py and add two ForeignKey declarations
to that model.

Hope that helps,

Ben

On 02/10/2007, Greg_IAP <[EMAIL PROTECTED]> wrote:
>
>
> HI, yesterday  i send a message which asks of using an existing
> database with Django.
>
> Thanks to the guy who has answered me, but i have to explain a little
> bit more my problem.
>
> I 'm in charge of developping an astronomic images and metadata
> database for scientists in mysql, composed by 9 tables with many
> relations between them (one to one, many to many, one to many) and
> among them there is image table which contains specific image field
> implemented by mysql "the polygon class".
> it permit to describe an astronomical image as a sky surface with 4
> points in spherical coordinates, i mean a bounding box around a part
> of the sky.It permit, for example, to know how many astronomic images
> of the database contains "M31 galaxy" object.
>
> Astronomic images are in the FITS format : there is headers containing
> metadata and an other part for pixels data.
>
> Here is for example the image table of the database
>
> CREATE TABLE image (
>   idimage INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
>   Channel_idChannel INTEGER UNSIGNED NOT NULL,
>   CalibrationKit_idCalibrationKit INTEGER UNSIGNED NOT NULL,
>   Run_idRun INTEGER UNSIGNED NOT NULL,
>   Instrument_idInstrument INTEGER UNSIGNED NOT NULL,
>   SkyFootPrint MULTIPOLYGON NULL,
>   AstromAccuracy DOUBLE PRECISION NULL,
>   EQUINOX DOUBLE PRECISION NULL,
>   Name VARCHAR(20) NULL,
>   OBJECT VARCHAR(80) NULL,
>   DATE_OBS  DATETIME NULL,
>   EXPTIME  DOUBLE PRECISION NULL,
>   AIRMASS DOUBLE PRECISION NULL,
>   PHOT_C DOUBLE PRECISION NULL,
>   Quality1 DOUBLE PRECISION NULL,
>   QUALITY2 DOUBLE PRECISION NULL,
>   IngestionFlags BIT(8) NULL,
>   IngestionDate DATETIME NULL,
>   ProcessingFlags BIT(8) NULL,
>   LastProcessingDate BIT(8) NULL,
>   ProcessingTimeZone CHAR(3) NULL,
>   ReferenceChip INTEGER UNSIGNED NULL,
>   PathURL VARCHAR(255) NULL,
>   UTC_OBS TIME NULL,
>   PRIMARY KEY(idimage),
>   INDEX image_FKIndex1(Instrument_idInstrument),
>   INDEX image_FKIndex2(Run_idRun),
>   INDEX image_FKIndex3(CalibrationKit_idCalibrationKit),
>   INDEX image_FKIndex4(Channel_idChannel)
> )
> TYPE=InnoDB;
>
> I create the database structure myself and the database is feeded
> using python scripts by scanning the headers of the images (containing
> metadata and others astronomical informations) and fill the database.
> But i need django to admin this database and to permit some users to
> consult it, display images, do queries ..........
>
> So many questions are present in my mind when i discovered what could
> be done with django...
>
> First and before the feeding of the database, after creating my
> database in the mysql prompt by inserting SQL code could django
> analyse my clean database and create class for each table?
> with the right field type?
> what happens if the field type does not exists in django ? (the case
> of POLYGON TYPE)
> is that mean that i can abandon or there is another way to go through
> this...
>
> How could i make django understand the relation between tables of my
> database, primary and foreign keys as shown in my image table?
>
> Coule it be done after the feed of the database or could i integrate
> my python scripts into my django application structure?
>
> i hope my explanations and questions will be understood...
>
> Thanks
>
> Greg
> Astrophysic Institute of Paris
>
>
> >
>


-- 
Regards,
Ben Ford
[EMAIL PROTECTED]
+6281317958862

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to