Django Object Manager Problem -


So here's a question for a Django wizard. I inherited the object manager in some way with lines:

  class MyObjManager (models.Manager): def total_values ​​(self, myobj_id): return 49 def what_the_heck (manually , Poll_id): return 48 square TestMe (): def what_the_heck (self, poll_id): return 47  

Now if I make a model that uses this object manager, then work as follows does not.

MyObj (models.Model): x = models.CharField (max_length = 200) y = Model. Dataimfield ('Date published') objects = MyObjManager () kb = MyObjManager () testMe = TestMe () DRF all_values ​​(self): # Return one self.objects.total_values ​​(1) #b Return self.objects.yyy (1) # Returns C.B.V.H_HEKAQ (1) #D Returns 50 # A Return Self TestMe.what_the_heck (1) #f Returns self.objects.what_the_heck (1)

Now it seems that A, B, C, D, E are at one time Respectively made a comment. Here are the results if I call myObj.total_values. (Where MyObj is an example of MyObj) A) Nothing B) Nothing C) None D) 50 E) 47 F) Nothing

I used two Object Managers in this example But it does happen that I only use one, why can not I use methods in my underlying object management manager? , B, and C. You can not use yourself ... This is an example method, and itself refers to that example ... in which an example does not have manager methods.

E and F work because, once again you are calling example methods, of which you have declared the properties properly.

For A, B, C, MyObj

  class MyObj (model): x = model.ccarfield (max_length = 200) y = model.Datetime field ( 'Publish Date') Objects = MyOzJanager () KB = MyOnJenner () testMe = TestMe () DRF total_value (auto): # Return MyOs .objects.total_values ​​(1) #B Return MyObj.objects.yyy (1) # C return MyObj.kb.what_the_heck (1) #D return 50 # Back Self Test. Me what_the_heck (1) #f return self.objects .what_the_heck (1)  

me ah It's time to think about the scenario, where you An example of the model will be found, and then call a function to get other examples of that model, though ... (I suggest that your approach may be weird or wrong, your big scope problem gives you better answers Can help.)


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -