Thank you for responding.
Yeah I was starting to figure out just what you're saying, that I
can't access the functions of a class within the class definition
itself. This is also true in PHP. In this case, if I were writing in
PHP I would do something like this:
function __construct(){
parent::__construct(); //because this is a subclass
$this->classification = $this->getClassificationTree();
}
I figured I should probably do a similar thing here using the __init__
function, but I have run into numerous problems. It seems I am having
trouble matching up the exact parameters of the class this one is
inheriting from. Believe it or not I can't even seem to find an API
page explaining all of the parameters, methods and properties of
ModelForm. I have gone back to the source but so far it hasn't helped
me. And I also can't find an example of someone extending ModelForm
and doing something this complicated - even though its really not that
complicated.
I've been stuck on this problem for a couple of days now. If you
could point me to a resource or provide any further guidance it would
be much appreciated.
Aaron
On Jan 27, 9:44 pm, Malcolm Tredinnick <[email protected]>
wrote:
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---