Re: models wierdness

2006-09-18 Thread Rob Hudson

Thanks for the reply.  :)


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



Re: models wierdness

2006-09-16 Thread Malcolm Tredinnick

Hi Rob,

On Tue, 2006-08-29 at 17:22 -0700, Rob Hudson wrote:
> I've got an app called page I've been working on.  Pages can contain
> text, graphics, or media and each have their own table which refer back
> to page (ForeignKey).  When I set up this model, only page_media has
> the inlined SQL for the foreign key ("REFERENCES"), where as the others
> do it with an ALTER TABLE syntax.  This seems odd to me that almost the
> identicle table definition is output differently.  Should I be
> concerned?  Should each table have similar SQL?

I see nobody answered this, so just in case you are still worried:

Don't be concerned. Whether we generate a "REFERENCES..." clause or an
"ALTER TABLE ..." statement is an artifact of the order in which the
various tables are constructed internally (somewhat related to Python's
dictionary hashing algorithm). The end result is the same, so the
difference is simply cosmetic. Note that all the "ALTER TABLE..."
statements are for what would have been illegal forward-references if we
had done them as inline "REFERENCES..." clauses.

We could maybe work around this in some cases by doing a topological
sort on the table creation structures, but it would be a non-trivial
internal rewrite of django.core.management and not necessarily worth the
effort (the code would become a little harder to maintain).

Regards,
Malcolm


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



models wierdness

2006-08-29 Thread Rob Hudson

I've got an app called page I've been working on.  Pages can contain
text, graphics, or media and each have their own table which refer back
to page (ForeignKey).  When I set up this model, only page_media has
the inlined SQL for the foreign key ("REFERENCES"), where as the others
do it with an ALTER TABLE syntax.  This seems odd to me that almost the
identicle table definition is output differently.  Should I be
concerned?  Should each table have similar SQL?

Thanks,
Rob

My models.py:

from django.db import models

class Template(models.Model):
name = models.CharField(maxlength=64, db_index=True,
unique=True)

def __str__(self):
return self.name

class Admin:
list_display = ('name')

class Page(models.Model):
name = models.CharField(maxlength=64, db_index=True,
unique=True)
template = models.ForeignKey(Template)

def __str__(self):
return self.name

class Admin:
list_display = ('name', 'template')

class Text(models.Model):
page = models.ForeignKey(Page, db_index=True,
edit_inline=models.STACKED)
position = models.CharField(maxlength=16, core=True)
content = models.TextField(core=True)

class Meta:
ordering = ['position']

class Graphic(models.Model):
page = models.ForeignKey(Page, db_index=True,
edit_inline=models.STACKED)
position = models.CharField(maxlength=16, core=True)
filename = models.CharField(maxlength=128, core=True)

class Meta:
ordering = ['position']

class Media(models.Model):
page = models.ForeignKey(Page, db_index=True,
edit_inline=models.STACKED)
position = models.CharField(maxlength=16, core=True)
filename = models.CharField(maxlength=128, core=True)

class Meta:
ordering = ['position']

The output of "./manage.py sql page":

BEGIN;
CREATE TABLE `page_text` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`page_id` integer NOT NULL,
`position` varchar(16) NOT NULL,
`content` longtext NOT NULL
);
CREATE TABLE `page_graphic` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`page_id` integer NOT NULL,
`position` varchar(16) NOT NULL,
`filename` varchar(128) NOT NULL
);
CREATE TABLE `page_page` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`name` varchar(64) NOT NULL UNIQUE,
`template_id` integer NOT NULL
);
ALTER TABLE `page_text` ADD CONSTRAINT page_id_refs_id_7038ecc2 FOREIGN
KEY (`page_id`) REFERENCES `page_page` (`id`);
ALTER TABLE `page_graphic` ADD CONSTRAINT page_id_refs_id_5fad2eb2
FOREIGN KEY (`page_id`) REFERENCES `page_page` (`id`);
CREATE TABLE `page_template` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`name` varchar(64) NOT NULL UNIQUE
);
ALTER TABLE `page_page` ADD CONSTRAINT template_id_refs_id_768003f7
FOREIGN KEY (`template_id`) REFERENCES `page_template` (`id`);
CREATE TABLE `page_media` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`page_id` integer NOT NULL REFERENCES `page_page` (`id`),
`position` varchar(16) NOT NULL,
`filename` varchar(128) NOT NULL
);
COMMIT;


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