On Tue, 2009-01-27 at 08:32 -0800, ajlozier wrote: > I have made a little progress on the problem I posted about earlier > (<a href="http://groups.google.com/group/django-users/browse_thread/ > thread/100679d9c298dc52/ffa1564be0c4b276?hl=en&lnk=gst&q=tree > +admin#ffa1564be0c4b276">creating tree inputs in the admin</a>) but am > getting stuck on what i am sure is a very minor point. > > warning, i am sure this is a very n00b question. i've only been using > django/python for about one week now. > > http://pastebin.com/d6bab03fe > > right now i am getting an error on line 19 - "two arguments are > required." but, if i try to pass self as the first argument, it says > self is not defined. > > my background is php - i am getting the feeling that self is not > necessarily the same thing as $this in php (or 'this' in javascript) > can someone illuminate what this means, why (if i do) have to have > self as the first argument in my def MyStyleAdminForm, and how i need > to pass it from within the class?
Well, "self" is kind of like $this or "this", but not precisely equivalent. You can't quite Use The Force like that when programming and it would be worthwhile doing a Python tutorial (e.g. the one at python.org) if this is a stumbling block. That being said.. The getClassificationTree() method is a method on the MyStyleAdminForm model. It is, in fact, an *instance* method, which means you can only call it on an instance of the model. The highly normal way to do this in Python is (if "foo" is an instance of MyStyleAdminForm): foo.getClassificationTree(parents) Also possible is MyStyleAdminForm.getClassificationTree(foo, parents) but that's less common and, for that reason, less advisable (as it will make anybody reading the code later wonder why you're doing things in an odd way). In your particular case, however, you have a more fundamental problem: you're trying to call an instance method on the class before you have an instance. Line 19 in that paste is executed at parse time -- when the module is first imported. Python is just constructing the class object at that point. Instances are only created much later on (when the admin wants to use that class). So something about your approach needs to be rethought there. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---