Re: Problem in Django App Part 1 Tutorial

2010-06-16 Thread !...@!!!
PO

On Jun 16, 6:55 pm, "!...@!!!"  wrote:
> P
>
> On Jun 16, 6:49 pm, "!...@!!!"  wrote:
>
>
>
> > Thanks Thierry, but problem solved!...:)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem in Django App Part 1 Tutorial

2010-06-16 Thread !...@!!!
P

On Jun 16, 6:49 pm, "!...@!!!"  wrote:
> Thanks Thierry, but problem solved!...:)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem in Django App Part 1 Tutorial

2010-06-16 Thread !...@!!!
Thanks Thierry, but problem solved!...:)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem in Django App Part 1 Tutorial

2010-06-16 Thread Thierry
I noticed you are importing your project name, are you invoking your
"python manage.py shell" from within your project folder?  If you are,
try the following:

project_folder/python manage.py shell
>>> from polls.models import Poll
>>> dir(Poll)

The above should show you that "was_published_today" method in a
list.  Try to call the method again:

>>> Poll.objects.get(pk=1).was_published_today()


On Jun 16, 8:08 am, "!...@!!!"  wrote:
> Hello,
> I am a Python newbie and this is my first time I use Django and
> Python.
> I was reading the Django App tutorial Part 1 and got stuck in a place.
>
> I execute these statements in the Python Shell:
>
> >>> from mysite.polls.models import Poll, Choice
> >>> import datetime
> >>> p = Poll(question="What's up?", pub_date=datetime.datetime.now())
> >>> p.save()
> >>> p = Poll.objects.get(pk=1)
> >>> p.was_published_today()
>
> For the last statement I get an error:
>
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'Poll' object has no attribute 'was_published_today'
>
> This is my "models.py" file:
>
> from django.db import models
> import datetime
>
> 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.question
>
> I wrote it with IDLE.
> I thought it was an indentation and whitespace problem, but I followed
> strictly the identation rules and used only tabs.
> Also I tried other editors and nothing changed. the error message
> still shows up.
> Please help me, what am I doing wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem in Django App Part 1 Tutorial

2010-06-16 Thread !...@!!!
Never mind I solved the problem!
For all of you with the same problem: it appears that the first time
that you use or import (i'm not really sure) a class in the python
shell, it's source-code file is compiled automatically in a ".pyc"
file, in the same directory where the source-code file is located and
with the same name.
After that everytime you import that class, the python interpreter
gets it from the ".pyc" file. You added the "was_published_today()"
method to the Poll class in the "models.py" file, but the "models.pyc"
file still contains the old version even after an re-import or reuse
of the Poll class. It seems that Python compiles the module only the
first time it is imported, and after that even if the source-code in
"models.py" changes, the python interpreter doesn't automatically
recompile the new version of the code. That's why the ".pyc" file
still has the old version of the Poll class and that's where the
Python interpreter imports the class from so you get the
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'Poll' object has no attribute 'was_published_today'
error in the interpreter.
I think that it has nothing to do with indentation or whitespaces. If
you delete the ".pyc" files for every file you change, then there
should be no more problems. Just go to polls/ directory and delete
"models.pyc" (or any other ".pyc" file if you had made changes to
"settings.py" or "urls.py").
Everything should work fine now.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem in Django App Part 1 Tutorial

2010-06-16 Thread !...@!!!
Never mind I solved the problem!
For all of you with the same problem: it appears that the first time
that you use or import (i'm not really sure) a class in the python
shell, it's source-code file is compiled automatically in a ".pyc"
file, in the same directory where the source-code file is located and
with the same name.
After that everytime you import that class, the python interpreter
gets it from the ".pyc" file. You added the "was_published_today()"
method to the Poll class in the "models.py" file, but the "models.pyc"
file still contains the old version even after an re-import or reuse
of the Poll class. It seems that Python compiles the module only the
first time it is imported, and after that even if the source-code in
"models.py" changes, the python interpreter doesn't automatically
recompile the new version of the code. That's why the ".pyc" file
still has the old version of the Poll class and that's where the
Python interpreter imports the class from so you get the
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'Poll' object has no attribute 'was_published_today'
error in the interpreter.
I think that it has nothing to do with indentation or whitespaces. If
you delete the ".pyc" files for every file you change, then there
should be no more problems. Just go to polls/ directory and delete
"models.pyc" (or any other ".pyc" file if you had made changes to
"settings.py" or "urls.py").
Everything should work fine now.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Problem in Django App Part 1 Tutorial

2010-06-16 Thread !...@!!!
Hello,
I am a Python newbie and this is my first time I use Django and
Python.
I was reading the Django App tutorial Part 1 and got stuck in a place.

I execute these statements in the Python Shell:

>>> from mysite.polls.models import Poll, Choice
>>> import datetime
>>> p = Poll(question="What's up?", pub_date=datetime.datetime.now())
>>> p.save()
>>> p = Poll.objects.get(pk=1)
>>> p.was_published_today()

For the last statement I get an error:

Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'Poll' object has no attribute 'was_published_today'


This is my "models.py" file:

from django.db import models
import datetime

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.question


I wrote it with IDLE.
I thought it was an indentation and whitespace problem, but I followed
strictly the identation rules and used only tabs.
Also I tried other editors and nothing changed. the error message
still shows up.
Please help me, what am I doing wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.