Why is this many-to-many relation changing whitout me asking for it, using the Django ORM?

I have a recursive M2M relationship with an indicator class. An indicator is a int, or a calculated value from 2 indicators:

class Indicator(models.Model):

    params = models.ManyToManyField('self', 
                                blank=True, null=True)

    type = models.CharField(max_length=64, verbose_name=__(u'type'))

    def get_value(self, record):

        # etc

According to the type, get_value doesn't do the same things. It can just return the numerical value or calculate a value from the numerical value of each parameters from the params attribute. As you can see params is a recursive m2m relationship.

Now my problem is that, I have the follwoing indicators:

  • men
  • women
  • total pop
  • men ratio

If I add men and women as parameters of total pop, everything is fine, and I get my total pop dynamically calculated. But if I then add men and total pop as parameters to men ratio, then total pop automatically get men ratio as a parameter. It breaks everything.

Why is that? How can I avoid it?


M2M relations in Django are symmetric by default ie in an M2M, if a related to b then b also related to a. To stop this, use symmetrical=False

your params would become:

params = models.ManyToManyField('self', 
                                blank=True, null=True,

Need Your Help

Problem in fitting the excel cell size to the size of the content when using apache poi

java apache-poi

I am beginner to Apache POI api. I am trying to create excel sheet using arraylist.

Joining two complex XSLT variables into a new one

xml xslt xslt-1.0

I like to import or include two or more externals xsl's to my main xsl.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.