Hi everyone,

We are developing a webapp using Django. We have found a problem with m2m relations.

I will Expose a simplified example of the problem; say we have 2 classes:

class A(models.Model):
name = models.CharField(max_length = 128, default="", blank = True, null=True, verbose_name = "Interface Name")

       def setName(self,value)
          #Do fancy validation
          self.name = value
          self.save()

class B(models.Model):
multipleAs = models.ManyToManyField('A', blank = True, null = False, editable = False)

        def modifyAnA(self,myName,newValue):
               #let's modify
               instance=self.multipleAs.get(name=myName)
               instance.setName(newValue)

With this code, the instance that was in the class B's m2m relation is missing, once I execute the setName method in the instance (instance is correctly modified in table of class A) (?¿). In addition, if I do the following:

        def modifyAnA(self,myName,newValue):
               #let's modify
               instance=self.multipleAs.get(name=myName)
               #instance.setName(newValue)
               instance.name = newValue
               instance.save()

Works perfectly, and the instance is already there. In addition, I am not using transactions for the moment.

Am I missing something trivial here? A bug? Is Django supposed to behave this way?

Although I know I will not be able to force the usage of the setters, we "must"use them since we don't want to be spreading around data validations outside the class (since are quite big, and not very beautiful).

Thank you in advance

B regards
Marc

p.s. By the way, working with stable Debian Squeeze 32 Django version, I belive version "Package: python-django (1.3-2)"

--
............................................................................
Marc Suñé Clos
Network Technologies Cluster (CTX)
i2CAT Foundation
C/ Gran Capità 2-4, office 203, Nexus I building
08034 Barcelona, Catalonia (Spain)

T: +34 93 567 9926
F: +34 93 553 2520

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

Reply via email to