[Answer]-Django models with a many to many relationship causing conflicting ordering requirements in models.py

1👍

Switch the order of these statements, so that your QueryJob is created first, then your PropertyQuery models are created:

def save(self, *args, **kwargs):
    super(QueryJob, self).save(*args, **kwargs)
    self.createqueries()

In your createqueries() method, you can refer to self when you need to create a link. Do not create a link to the primary key directly as this won’t work – you don’t realize its not working because you have a blank except clause that is catching the exceptions raised:

def createqueries(self):
    #json_data = json.loads(self.Json)
    print self.Json
    for each in self.Json:
        Street = each.get(self.street_column)
        State = each.get(self.state_column)
        Suburb = each.get(self.suburb_column)
        Postcode = each.get(self.postcode_column)
        q = PropertyQuery(street_address = Street,
                          state=State,
                          suburb = Suburb,
                          postcode=Postcode,
                          queryID=self)
        q.save()

Leave a comment