On Wed, 2009-01-28 at 05:53 -0800, ajlozier wrote:
> 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.  

I don't understand what this means. Can you be a bit more specific?

There are examples all over the Django code (including
ModelFormBase.__init__) or __init__ methods calling their parent class's
__init__ method. Search for calls to "super()", which is the standard
way to call the next method in the name resolution order.

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

Then "API documentation" wouldn't really add much value; it would simply
repeat the code, in effect (rewriting everything in English again). We
have documentation describing standard ModelForm usage and we prefer
holistic descriptions to API dumps. The source isn't particularly
complicated: everything inherits from BaseModelForm and the __init__
method's parameters are named for their purpose and they have the same
names as the parameters in BaseForm.

Hopefully (and necessarily, really) before diving into creating
derivatives of ModelForm, one has a good general understanding of how
Django Form subclasses work -- that is what parameters like "data" and
"initial" and "error_class" are for. Again, if you have specific
questions, ask. But the ideal way to learn this is to create forms for a
bunch of different cases and then slowly extend and enhance.

>  And I also can't find an example of someone extending ModelForm
> and doing something this complicated - even though its really not that
> complicated.

Debating whether something's complicated or not is not particularly
productive, so I don't really want to have an opinion here. Once you've
worked it out, it will probably seem straightforward. Based on the
questions you're asking (such as how to call instance methods), though,
it seems like you're still wrestling with learning the language, which
makes this a kind of odd first project to take on. That shouldn't be a
discouragement to continue persisting -- having a non-trivial project as
the driving goal is a good idea -- but it also shouldn't be too
surprising if it does take a fair bit of time.

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

Reply via email to