Thankyou! so much...!

It was because i had tabs instead of 4 spaces for the indents.
So basically it was an indentation error but it didn't say that in the 
console.

I think this will fix a lot of other peoples problems if they are using 
tabs instead of spaces for indentations.

Cheers.

On Thursday, 27 March 2014 10:53:29 UTC, Shai Efrati wrote:
>
> i wonder if it is just the formatting of the email, but i think you missed 
> spaces before your def. def are hierarchically under classes, so it should 
> be:
>
> import datetime
> from django.db import models
> from django.utils import timezone
>
> # Create your models here.
> class Poll(models.Model):
>     question = models.CharField(max_length=200)
>     def __unicode__(self):
> return self.question
>     pub_date = models.DateTimeField('date published')
>     def was_published_recently(self):
>           return self.pub_date >= timezone.now() - 
> datetime.timedelta(days=1)
>
> class Choice(models.Model):
>     poll = models.ForeignKey(Poll)
>     choice_text = models.CharField(max_length=200)
>     votes = models.IntegerField(default=0)
>     def __unicode__(self):
>  return self.choice_text
>
>
> Good luck!
>
>
> Shai.
>
>
> On Thu, Mar 27, 2014 at 12:06 PM, Steve Evans <00se...@gmail.com<javascript:>
> > wrote:
>
>> Hi I am having the same issue:
>>
>> I am using Python 2.7, and Django 1.6.
>>
>> Here is my code for models.py:
>>
>> import datetime
>> from django.db import models
>> from django.utils import timezone
>>
>> # Create your models here.
>> class Poll(models.Model):
>>     question = models.CharField(max_length=200)
>> def __unicode__(self):
>> return self.question
>>
>> pub_date = models.DateTimeField('date published')
>> def was_published_recently(self):
>> return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
>>
>> class Choice(models.Model):
>>     poll = models.ForeignKey(Poll)
>>     choice_text = models.CharField(max_length=200)
>>     votes = models.IntegerField(default=0)
>> def __unicode__(self):
>> return self.choice_text
>>
>>
>> I have restarted the shell and this is what I get as a result:
>>
>> bash-3.2$ python manage.py shell
>>
>> Python 2.7.6 (default, Dec 19 2013, 06:00:47) 
>>
>> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
>>
>> Type "help", "copyright", "credits" or "license" for more information.
>>
>> (InteractiveConsole)
>>
>> >>> from polls.models import Poll, Choice
>>
>> >>> Poll.objects.all()
>>
>> [<Poll: Poll object>, <Poll: Poll object>]
>>
>> >>> exit()
>>
>> bash-3.2$ python manage.py shell
>>
>> Python 2.7.6 (default, Dec 19 2013, 06:00:47) 
>>
>> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
>>
>> Type "help", "copyright", "credits" or "license" for more information.
>>
>> (InteractiveConsole)
>>
>> >>> from polls.models import Poll, Choice
>>
>> >>> Poll.objects.all()
>>
>> [<Poll: Poll object>, <Poll: Poll object>]
>>
>> >>> 
>> Any help would be great...
>>
>> Cheers,
>> Steve
>>
>>
>>
>> On Sunday, 12 January 2014 14:34:22 UTC, shmengie wrote:
>>>
>>>  trojactory has the right idea.
>>>
>>> __unicode__ has two underscores on either side of _ _ unicode _ _
>>>
>>> If you don't spell __unicode__ with two underscores on both sides, you 
>>> are not overriding the default method __unicode__ 
>>>
>>> You are getting the default output for __unicode__ instead of the 
>>> expected.
>>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/114e5208-81b6-4068-82df-853176ebfd68%40googlegroups.com<https://groups.google.com/d/msgid/django-users/114e5208-81b6-4068-82df-853176ebfd68%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a2d77f15-84ce-47cb-9b23-5dbc1827e65b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to