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
def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
def __unicode__(self):
return self.choice
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.
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
You want 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
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
def __unicode__(self):
return self.choice
But this mixes tabs and spaces.
Rules:
1. Don't use tabs!
2. If you are clueless enough to violate (1), then don't mix tabs and
spaces.
3. Don't use tabs!
Tabs are for tables, hence the name. "Use spaces for space and use tabs
for tables" can be a little mnemonic to help you remember the rules. We
can make a little song together if you can think of some things that
rhyme with "don't" and "use" and "tabs".
You have been warned. Next time I'll piont and laugh as I answer.
James
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
Laughing to hard at the tab & spaces thing to notice the lack of
indentation here.
"won't"
"blues", "booze", "bruise", "choose", "cruise", "fuse", "hues",
"Jews", "lose", "muse", "news", "snooze", "views", etc.
"abs", "cabs", "crabs", "dabs", "grabs", "labs", "scabs", "slabs",
"stabs", etc.
When you want to screw your whitespace--don't!
Take this little pledge and I know you won't:
When I was in school I would take of booze
While my typing teacher said I'm free to use
Space or formfeed or even tabs
And I punched so hard with my pinkie that scabs
Covered my Jake and Elwood tatoos.
(You didn't see that one coming did yous?)
> When you want to screw your whitespace--don't!
> Take this little pledge and I know you won't:
James, you're a poet
And you don't even realise
--
\ "[...] a Microsoft Certified System Engineer is to information |
`\ technology as a McDonalds Certified Food Specialist is to the |
_o__) culinary arts." —Michael Bacarella |
Ben Finney
I'm so confused, I have no idea what's going on...