On Tue, Nov 29, 2011 at 3:44 PM, Marc Edwards <jmarcedwa...@gmail.com> wrote: > I need some help in resetting my thinking on creating my Django data > model. > > I have previously created an XML schema definition for my data model, > but am now trying to re-create this XML data model in a Django data > model. > > In my XML schema, I had defined "collections" of XML complex types > that essentially were lists that I could XQuery. I used the ID & > IDREF tags to cross-reference my elements between lists of elements. > As XML is a tree structure, my schema defined a top down tree > hierarchy. Now I want to redefine this in a Django data model. > > In my primary scenario, I had a list of "singular" workflows that > constituted a "parent" element "catalog" of workflows, i.e. a workflow > catalog. Multiple "singular" workflows can be combined into an ORDERED > collection of workflows called a "reference" or "composite" workflow. > There are many composite/reference workflow instances with varied > ordered combinations of singular workflows. > > In my XML hierarchy, I used the IDREF tags to reference the "singular" > workflows from within the "reference" workflow element instance. > > In my Django object model, I can define a class for a "singular" > workflow...easy enough, and I can query the Django database model to > select the "singular" workflows. > > But, what is the correct method of now creating the "composite" > workflow that will reference the singular workflows? > > My pseudo-code for the composite workflow class looks like this... > > class SingularWorkFlow(models.Model): > pass > > class CompositeWorkflow(models.Model): > OrderedListOfSingularWorkflows = > list(models.ForeignKey(SingularWorkFlow) > > I don't think this will work, but would kindly ask for some guidance. > > Regards, Marc
"An ordered list of related models" sounds to me like "Many To Many with a through model which has an ordering". https://docs.djangoproject.com/en/1.3/topics/db/models/#intermediary-manytomany You may want to specify a different manager for that relationship, so that the querysets are always ordered correctly: https://docs.djangoproject.com/en/1.3/topics/db/managers/#controlling-automatic-manager-types On the other hand, you may not, ordering is expensive: https://docs.djangoproject.com/en/1.3/ref/models/querysets/#order-by Cheers Tom -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.