I see I am talking about concepts which are not yet familiar to you.
By template I mean Django's HTML template engine. This is introduced
in part 3 of the tutorial.
The reason for the errors is that Poll is not an instance, it is the
class so it doesn't have pub_date. poll isn't assigned to yet. You
could do poll = Poll.objects.all()[0], and then poll would be assigned
the first Poll object instance, fetched from the database.
- Anssi
On May 1, 9:45 pm, Dan Santos <
dansanto...@gmail.com> wrote:
> Hi thanks for taking the time to explain to me!
>
> Unfortunately I still don't understand the outputs that I get in Python
> console, maybe it's because I don't understand the concept of templates.
> But this is what I tried to do in Python console.
>
> >>> p=Poll(question="Giddeup'ah!", pub_date=timezone.now())
> >>> p.save()
> >>>
p.id
> 4
> >>> p.question
> "Giddeup'ah!"
> >>> *p.pub_date*
>
> datetime.datetime(2012, 5, 1, *18, 25*, 39, 804854, tzinfo=<*UTC*>)
>
> >>> *Poll.objects.all()*
>
> [<Poll: Waddup'ah? 2012-04-26 08:39:20.605340+00:00>, <Poll: What's up?
> 2012-04-26 10:30:23.624835+00:00>,
> <Poll: How do you do? 2012-04-26 20:34:33.337247+00:00>, <Poll: Giddeup'ah!
> 2012-05-01 *18:25*:39.804854*+00:00*>]
>
> p.pub_date and Poll.objects.all() show the same time info, so how do I see
> the time with the simplest of templates?
>
> Also when I tried typing "poll.pub_date" in different ways I get these
> errors.
>
> >>> *Poll.pub_date*
>
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> AttributeError: type object 'Poll' has no attribute 'pub_date'
>
> >>> *poll.pub_date*
>
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> NameError: name 'poll' is not defined
>
> >>> *poll.pub_date()*
>
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> NameError: name 'poll' is not defined
>
> >>> *Poll.pub_date()*
>
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> AttributeError: type object 'Poll' has no attribute 'pub_date'
>
> Here's a better overview of what my relevant files looks like and what
> setup I have tried to use. Maybe it will help in finding if I
> have mis-configured something.
http://www.python-forum.org/pythonforum/viewtopic.php?f=19&t=34082