Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7561049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:04:01+00:00 2026-05-30T13:04:01+00:00

I am working on importing XML data into Django models. For example, I could

  • 0

I am working on importing XML data into Django models. For example, I could use the following XML:

<family surname="Jones">
    <person name="Bob" />
</family>

to populate the following Django models:

class Family(models.Model):
    surname = models.CharField(max_length=255)

class Person(models.Model):
    family = models.ForeignKey(Family, related_name="people")
    name = models.CharField(max_length=255)

In the XML, there is the concept of ‘triggers’ with ‘conditions’. For example:

<trigger>
    <condition ... />
    <action>Do something</action>
</trigger>

A trigger may have one condition-type element, where ‘condition-type’ means either a condition element or an element containing a group of condition elements (ie. and or or), which are to be read as ‘if all the conditions evaluate’ or ‘if some of the conditions evaluate’. Each ‘condition group’ may in turn contain one or more condition-type elements. A more complex example follows:

<trigger>
    <and>
        <condition />
        <or>
            <condition />
            <condition />
            <and>
                <condition />
                <condition />
            </and>
        </or>
    </and>
    <action>Do something</action>
</trigger>

I can’t figure out the best way to model this with Django. Ideally I’d like the Trigger model to link to an abstract ConditionType model (which can be either a Condition or a ConditionGroup), and the ConditionGroup model (but not the Condition model) to link to multiple ConditionType models.

I’m reasonably new to Django models. I have read the documentation with regards to model inheritance, but still can’t figure out how to model something quite so complex as this. Does anyone have any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:04:03+00:00Added an answer on May 30, 2026 at 1:04 pm

    So, I eventually solved the problem by having the following three classes: ConditionGroup, SubConditionGroup and Condition. SubConditionGroup inherits from ConditionGroup. ConditionGroups may be of type ‘single’, ‘and’ or ‘or’, where ‘single’ contains a Condition and the other two can contain multiple SubConditionGroups.

    So, my finished model looks something like this:

    class Trigger(Model):
        ...
        condition_group = ForeignKey(...)
    
    
    class ConditionGroup(Model):
        type = CharField(...)  # options="and"|"or"|"single"
        condition = OneToOneField(..., null=True, blank=True)
    
    
    class SubConditionGroup(ConditionGroup):
        parent = ForeignKey(ConditionGroup, ...)
    
    
    class Condition(Model):
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on importing XML into an iPad Core Data application. I have
Forum- After an importing a previously working package into my Eclipse IDE All of
I have a winapp which writes data into a xml(Data.xml). This xml is my
I'm working with Solr 3.5.0. I am importing from a JDBC data source and
I've got some code to convert a large (many gigabytes) XML file into another
Scenario: I'm working on a rails app that will take data entry in the
I'm working on a web service that fetches data from an oracle data source
I've got a treeview bound to an XmlDataProvider following this example . The app
I'm working my way into MVC at the moment, but on my To learn
I have this code for an app i'm working on: <?php header(Content-type: text/xml); //Gather

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.