You would normally do:
class User(models.Model):
def __init__(self):
name = ...
but this looks not cool) That's why most of python libraries use "declarative" syntax to describe models:
class User(models.Model):
name = ...
And then behind the scenes they just hide that name variable somewhere and create another name object-variable.
I think that is frustrating for newbies and lots of other users since it's hard to understand difference between object-properties and class-properties)
That's one of things why python is broken, imho. But it's still better then everything else)
02.03.2011, 23:02, "Alex Hall" <mehgcap@gmail.com>;:
> 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.
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehgcap@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+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
jabber: k.bx@ya.ru
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment