python - Django runtime error during insertion from admin -


itemprop = "text">

I have a Django model as follows:

  class M1 (models. Model): m1code = models.CharField (MAX_LENGTH = 25) m1title = models.CharField (MAX_LENGTH = 500) m1description = models.CharField (MAX_LENGTH = 1000, null = true, blank = true) def __unicode __ (self): return self .m1title class M2 (MPTTModel): M 1 = models.ForeignKey (M1) name = models.CharField (MAX_LENGTH = 500, unique = false) parent = TreeForeignKey ( 'self', null = true, blank = true, related_name = 'Children') DEF __unicode__ (self): return self.name def save (self, * args, ** kwargs): degreeroot = M2.objects.get (Name = self.m1.m1title) requires = M2.objects.create (name = self.name, parents = degreeroot, m1 = self.m1)  

Here's a model to me M2 (MPTT model) is a foreign key of M1. Whenever I enter an entry from the admin in M2, then I want DJenggo to enter the value of the mother in M2 on the basis of selection of M1.

Here I have defined a saved () to do this. But when I'm running this in my admin, the program is going in a runtime error .

  at / admin / Acadprog / m2 / add / max recursion depth RuntimeError   

You do not want to create a new entry, because it always has an infinite It will be repetitive. If you just want to set the self.parent , call the method of saving the superclass to:

  def save (self, * Arges, ** kwargs): If not self-parents: self.parent = M2.objects.get (name = self.m1.m1title) return super (M2, self) .save (* args, ** kwargs)  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -