beginner whitespace question

eggie5 eggie5 at gmail.com
Thu Aug 9 21:13:24 EDT 2007


But this still isn't valid:

from django.db import models

class Poll(models.Model):
	question = models.CharField(max_length=200)
	pub_date = models.DateTimeField('date published')

    def __unicode__(self):
		return self.question



class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

    def __unicode__(self):
		return self.choice


On Aug 9, 5:52 pm, Dan Bishop <danb... at yahoo.com> wrote:
> On Aug 9, 7:02 pm, eggie5 <egg... at gmail.com> wrote:
>
>
>
> > On Aug 9, 4:52 pm, Dan Bishop <danb... at yahoo.com> wrote:
>
> > > On Aug 9, 6:47 pm, eggie5 <egg... at gmail.com> wrote:
>
> > > > I keep getting an error for line 7, what's wrong with this?
>
> > > > from django.db import models
>
> > > > class Poll(models.Model):
> > > >     question = models.CharField(max_length=200)
> > > >     pub_date = models.DateTimeField('date published')
>
> > > >         def __unicode__(self):
> > > >                 return self.question
>
> > > The "def" statements have to be at the same indentation level as
> > > what's before it.
>
> > will they still be a part of the classes?
>
> If you indent them twice, it's a syntax error.
> If you indent them once, they'll be methods of the class.
> If you don't indent them at all, they'll be global functions.





More information about the Python-list mailing list