On 3 March 2011 08:02, Alex Hall <mehg...@gmail.com> wrote:
> Hi all,
> Still working through that tutorial. I am just curious: why are none
> of the class variables called self.var, but rather just var? For
> example:
> import models
> class Poll(models.Model):
>  question=models.CharField(max_length=200)
>
> Should that not be
> self.question=...
> instead? Otherwise, saying something like:
> poll=Poll()
> poll.question="question?"
> should not work; question is not told to be part of the class by way
> of self. This may stray from django and into pure python territory, so
> sorry if it gets off-topic. I have never seen a class that does not
> tie its variables to itself with self or some other keyword. Come to
> think of it, there is no __init__ method. I know that it is not
> necessary to have one, but I figured I would have seen one to get
> things set up.

Django uses the magic of metaclasses to build model instances - see
http://code.djangoproject.com/browser/django/trunk/django/db/models/base.py#L26

> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com; http://www.facebook.com/mehgcap
>
> --
> 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.
>
>

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