On 4/19/06, njharman <[EMAIL PROTECTED]> wrote:

Trying to make a "choose your own adventure" like application so
chapters don't have an "order" but knowing the starting chapter is
required.  I can't figure out how to define the model.

class Story(meta.Model):
    start_chapter = meta.OneToOneField(Chapter) #Chapter not defined yet

class Chapter(meta.Model):
    story = meta.ForeignKey(Story)

Unfortunately, this isn't possible in 0.91/trunk. However, in the magic-removal stream, you can forward reference a model using the string version of the model name.

As for your database design - my only suggestion would be to seriously consider if you actually need the 'Story' model. IMHO, the following would be a better design for your app:

class Chapter(meta.Model):
    source = meta.ForeignKey('self', null=True, blank=True)

This establishes that every chapter has a link from a source chapter. You can get the starting chapter by searching for the chapter for which the source is None:

starting_chapter = Chapter.get_object(source__isnull=True)

This would also act as a workaround, because ForeignKey on self works in 0.91.

Yours,
Russ Magee %-)


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

Reply via email to