Re: Tutorial method was_published_today() - problem

2008-07-02 Thread bruno desthuilliers



On 2 juil, 09:48, Collin Grady <[EMAIL PROTECTED]> wrote:
> You can use tabs,

You can, but *don't*. Use spaces. 4 spaces. Always.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Tutorial method was_published_today() - problem

2008-07-02 Thread Collin Grady

You can use tabs, but you have to /always/ use tabs if you do so - you
can't mix tabs and spaces, or you hit issues like this :)

Especially if your editor is showing tabs as four spaces, since python
would use eight.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Tutorial method was_published_today() - problem

2008-07-01 Thread [EMAIL PROTECTED]

Got it. I had to delete the tabs and use spaces. I guess I won't cut/
paste or use tabs.

Thanks,

Jason

On Jul 1, 5:23 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Tue, Jul 1, 2008 at 8:06 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > It IS indented correctly, it looks like it wasn't due to copy/paste
> > but it is in fact inline with def __str__(self): BTW running .96.1
>
> I don't know what to tell you.  Cut/pasting your models, fixing the
> indentation, and cut/paste your shell queries works properly on my machine.
> Are you sure you have not mixed tabs and spaces and so have something that
> looks in your editor like it is indented properly when in fact the
> was_published_today() definition is indented too far as far as Python is
> concerned?
>
> Karen
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Tutorial method was_published_today() - problem

2008-07-01 Thread Karen Tracey
On Tue, Jul 1, 2008 at 8:06 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> It IS indented correctly, it looks like it wasn't due to copy/paste
> but it is in fact inline with def __str__(self): BTW running .96.1
>

I don't know what to tell you.  Cut/pasting your models, fixing the
indentation, and cut/paste your shell queries works properly on my machine.
Are you sure you have not mixed tabs and spaces and so have something that
looks in your editor like it is indented properly when in fact the
was_published_today() definition is indented too far as far as Python is
concerned?

Karen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Tutorial method was_published_today() - problem

2008-07-01 Thread [EMAIL PROTECTED]

It IS indented correctly, it looks like it wasn't due to copy/paste
but it is in fact inline with def __str__(self): BTW running .96.1

On Jul 1, 12:26 pm, Matthias Kestenholz <[EMAIL PROTECTED]> wrote:
> On Tue, 2008-07-01 at 12:18 -0700, [EMAIL PROTECTED] wrote:
> > Hello,
>
> > I'm just going through this tutorial and the custom method
> > was_published_today() is not recognized as an attribute of Poll,
> > though it's defined in the model as follows:
>
> > from django.db import models
> > import datetime
>
> > class Poll(models.Model):
> > question = models.CharField(maxlength=200)
> > pub_date = models.DateTimeField('date published')
> > def __str__(self):
> > return self.question
> >def was_published_today(self):
> >return self.pub_date.date() == datetime.date.today()
>
> Your indentation is wrong. was_published_today is an inner function of
> __str__ instead of being a class method of its own. 'def
> was_published_today' should have the same indentation as 'def __str__'
>
> Please be very careful with whitespace when writing python/django code!
>
> Btw, are you using version 0.96.x of Django or a SVN checkout? You
> should use __unicode__ instead of __str__ in code written for a current
> version of Django. This does not matter for the problem you run into,
> I'm just asking.
>
> Matthias
>
> --http://spinlock.ch/blog/
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Tutorial method was_published_today() - problem

2008-07-01 Thread [EMAIL PROTECTED]

oops, it is, that was a result of copy/paste.

On Jul 1, 12:23 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Tue, Jul 1, 2008 at 3:18 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > Hello,
>
> > I'm just going through this tutorial and the custom method
> > was_published_today() is not recognized as an attribute of Poll,
> > though it's defined in the model as follows:
>
> > from django.db import models
> > import datetime
>
> > class Poll(models.Model):
> >question = models.CharField(maxlength=200)
> >pub_date = models.DateTimeField('date published')
> >def __str__(self):
> >return self.question
> >def was_published_today(self):
> >return self.pub_date.date() == datetime.date.today()
>
> Indentation is significant in Python.  You need to un-dent
> was_published_today() so that it is indented just as far as the def
> __str__(), not nested inside __str__().
>
> Karen
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Tutorial method was_published_today() - problem

2008-07-01 Thread Matthias Kestenholz

On Tue, 2008-07-01 at 12:18 -0700, [EMAIL PROTECTED] wrote:
> Hello,
> 
> I'm just going through this tutorial and the custom method
> was_published_today() is not recognized as an attribute of Poll,
> though it's defined in the model as follows:
> 
> from django.db import models
> import datetime
> 
> class Poll(models.Model):
> question = models.CharField(maxlength=200)
> pub_date = models.DateTimeField('date published')
> def __str__(self):
> return self.question
>   def was_published_today(self):
>   return self.pub_date.date() == datetime.date.today()
> 

Your indentation is wrong. was_published_today is an inner function of
__str__ instead of being a class method of its own. 'def
was_published_today' should have the same indentation as 'def __str__'

Please be very careful with whitespace when writing python/django code!


Btw, are you using version 0.96.x of Django or a SVN checkout? You
should use __unicode__ instead of __str__ in code written for a current
version of Django. This does not matter for the problem you run into,
I'm just asking.

Matthias


-- 
http://spinlock.ch/blog/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Tutorial method was_published_today() - problem

2008-07-01 Thread Karen Tracey
On Tue, Jul 1, 2008 at 3:18 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

>
> Hello,
>
> I'm just going through this tutorial and the custom method
> was_published_today() is not recognized as an attribute of Poll,
> though it's defined in the model as follows:
>
> from django.db import models
> import datetime
>
> class Poll(models.Model):
>question = models.CharField(maxlength=200)
>pub_date = models.DateTimeField('date published')
>def __str__(self):
>return self.question
>def was_published_today(self):
>return self.pub_date.date() == datetime.date.today()
>
>
Indentation is significant in Python.  You need to un-dent
was_published_today() so that it is indented just as far as the def
__str__(), not nested inside __str__().

Karen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Tutorial method was_published_today() - problem

2008-07-01 Thread [EMAIL PROTECTED]

Hello,

I'm just going through this tutorial and the custom method
was_published_today() is not recognized as an attribute of Poll,
though it's defined in the model as follows:

from django.db import models
import datetime

class Poll(models.Model):
question = models.CharField(maxlength=200)
pub_date = models.DateTimeField('date published')
def __str__(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(maxlength=200)
votes = models.IntegerField()
def __str__(self):
return self.choice

Here is the shell output:

>>> from mysite.polls.models import Poll, Choice
>>> p = Poll.objects.get(pk=1)
>>> p.was_published_today()
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'Poll' object has no attribute 'was_published_today'
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---