Writing your first Django app, part 1 - Django 1.7 - # Make sure our __str__() addition worked.

2015-02-04 Thread Gavin Patrick McCoy
Hi,

Just started learning Django today. I got down to the last grey box of code 
on 
https://docs.djangoproject.com/en/1.7/intro/tutorial01/#writing-your-first-django-app-part-1
 and 
when I checked to see of the __str__() addition to models.py worked, it 
didn't. I didn't get [], I got []. I tried creating a new question again and did but now I get  
[, ]. I then tried 'the 
three-step guide to making model changes: Change your models (in models.py). 
Run python manage.py makemigrations 

 
to create migrations for those changes. Run python manage.py migrate 
 
to apply those changes to the database.' I still got  [, ]. Any ideas? Any help would be greatly 
appreciated. 

Thanks, Gavin

My models.py looks like this: 

import datetime
from django.db import models
from django.utils import timezone
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

def _str_(self):
return self.question_text

def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

class Choice(models.Model):
question = models.ForeignKey(Question)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str(self):
return self.choice_text

-- 
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/e518a27e-da82-4c93-884f-a7a941d23853%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing your first Django app, part 1 - Django 1.7 - # Make sure our __str__() addition worked.

2015-02-04 Thread Gavin Patrick McCoy
Sorry about that. Thanks a million for your reply.

On Wednesday, 4 February 2015 17:38:16 UTC, Vijay Khemlani wrote:
>
> The method is called "__str__" (note the double underscore at both ends)
>
> On Wed, Feb 4, 2015 at 2:29 PM, Gavin Patrick McCoy  > wrote:
>
>> Hi,
>>
>> Just started learning Django today. I got down to the last grey box of 
>> code on 
>> https://docs.djangoproject.com/en/1.7/intro/tutorial01/#writing-your-first-django-app-part-1
>>  and 
>> when I checked to see of the __str__() addition to models.py worked, it 
>> didn't. I didn't get [], I got [> Question object>]. I tried creating a new question again and did but now 
>> I get  [, ]. I 
>> then tried 'the three-step guide to making model changes: Change your 
>> models (in models.py). Run python manage.py makemigrations 
>> <https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-makemigrations>
>>  
>> to create migrations for those changes. Run python manage.py migrate 
>> <https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-migrate>
>>  
>> to apply those changes to the database.' I still got  [> Question object>, ]. Any ideas? Any help 
>> would be greatly appreciated. 
>>
>> Thanks, Gavin
>>
>> My models.py looks like this: 
>>
>> import datetime
>> from django.db import models
>> from django.utils import timezone
>> # Create your models here.
>> class Question(models.Model):
>> question_text = models.CharField(max_length=200)
>> pub_date = models.DateTimeField('date published')
>> 
>> def _str_(self):
>> return self.question_text
>> 
>> def was_published_recently(self):
>> return self.pub_date >= timezone.now() - 
>> datetime.timedelta(days=1)
>> 
>> class Choice(models.Model):
>> question = models.ForeignKey(Question)
>> choice_text = models.CharField(max_length=200)
>> votes = models.IntegerField(default=0)
>> def __str(self):
>> return self.choice_text
>>
>> -- 
>> 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 .
>> To post to this group, send email to django...@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/e518a27e-da82-4c93-884f-a7a941d23853%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/e518a27e-da82-4c93-884f-a7a941d23853%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/6acc2808-2fe9-4643-9d17-c5eaec00e592%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Writing your first Django app, part 5 Testing

2015-02-21 Thread Gavin Patrick McCoy
Hi, 

I'm on part 5 of the polls tutorial 
(https://docs.djangoproject.com/en/1.7/intro/tutorial05/) and I am running 
Django 1.7 and Python 3.4 on Windows 8. Just want to make sure I'm on the 
right track.

For the following part of tutorial:

>>> # get a response from '/'>>> response = client.get('/')>>> # we should 
>>> expect a 404 from that address>>> response.status_code404>>> # on the other 
>>> hand we should expect to find something at '/polls/'>>> # we'll use 
>>> 'reverse()' rather than a hardcoded URL>>> from django.core.urlresolvers 
>>> import reverse>>> response = client.get(reverse('polls:index'))>>> 
>>> response.status_code200>>> response.content'\n\n\nNo polls are 
>>> available.\n\n' *<-Not getting this. See below. Seeing What's 
>>> up?*>>> # note - you might get unexpected results if your ``TIME_ZONE``>>> 
>>> # in ``settings.py`` is not correct. If you need to change it,>>> # you 
>>> will also need to restart your shell session>>> from polls.models import 
>>> Question>>> from django.utils import timezone>>> # create a Question and 
>>> save it>>> q = Question(question_text="Who is your favorite Beatle?", 
>>> pub_date=timezone.now())>>> q.save()>>> # check the response once again>>> 
>>> response = client.get('/polls/')>>> response.content'\n\n\n\n\n 
>>>Who is your favorite Beatle?\n
>>> \n\n\n' *Seeing What's up? here too.*
>>> # If the following doesn't work, you probably omitted the call to>>> # 
>>> setup_test_environment() described above>>> 
>>> response.context['latest_question_list'][>> Beatle?>] *Seeing What's up? here too*


Instead of getting '\n\n\nNo polls are available.\n\n' , the What's 
up poll is coming up i.e. b'r\n\t\r\n\t\r\n\t\tWhat'se up?\r\n\t\r\n\t\r\n? The rest of the 
code works fine as in adding the Beatles question but the What's up? question 
is also coming up along with the Beatles question. Is this ok? Any help would 
be greatly appreciated.

Thanks,

Gavin

-- 
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/fc23070f-8f90-4c4c-925a-94c24d3ee8bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing your first Django app, part 5 Testing

2015-02-21 Thread Gavin Patrick McCoy
I got a code 200. Thanks for your reply.

On Saturday, 21 February 2015 11:05:35 UTC, 严超 wrote:
>
> I think the purpose here is to test reverse() function. As long as you 
> got code 200, it's ok whatever html it returns.
> Is it right ?
>
> *Best Regards!*
>
>
> *Chao Yan--About me : http://about.me/chao_yan 
> <http://about.me/chao_yan>*
>
> *My twitter: @yanchao727 <https://twitter.com/yanchao727>*
> *My Weibo: http://weibo.com/herewearenow <http://weibo.com/herewearenow>*
> *------*
>  
> 2015-02-21 18:41 GMT+08:00 Gavin Patrick McCoy  >:
>
>> Hi, 
>>
>> I'm on part 5 of the polls tutorial (
>> https://docs.djangoproject.com/en/1.7/intro/tutorial05/) and I am 
>> running Django 1.7 and Python 3.4 on Windows 8. Just want to make sure I'm 
>> on the right track.
>>
>> For the following part of tutorial:
>>
>> >>> # get a response from '/'>>> response = client.get('/')>>> # we should 
>> >>> expect a 404 from that address>>> response.status_code404>>> # on the 
>> >>> other hand we should expect to find something at '/polls/'>>> # we'll 
>> >>> use 'reverse()' rather than a hardcoded URL>>> from 
>> >>> django.core.urlresolvers import reverse>>> response = 
>> >>> client.get(reverse('polls:index'))>>> response.status_code200>>> 
>> >>> response.content'\n\n\nNo polls are available.\n\n' 
>> >>> *<-Not getting this. See below. Seeing What's up?*>>> # note - you 
>> >>> might get unexpected results if your ``TIME_ZONE``>>> # in 
>> >>> ``settings.py`` is not correct. If you need to change it,>>> # you will 
>> >>> also need to restart your shell session>>> from polls.models import 
>> >>> Question>>> from django.utils import timezone>>> # create a Question and 
>> >>> save it>>> q = Question(question_text="Who is your favorite Beatle?", 
>> >>> pub_date=timezone.now())>>> q.save()>>> # check the response once 
>> >>> again>>> response = client.get('/polls/')>>> response.content'\n\n\n
>> >>> \n\nWho is your favorite 
>> >>> Beatle?\n\n\n\n' *Seeing What's up? here too.*
>> >>> # If the following doesn't work, you probably omitted the call to>>> # 
>> >>> setup_test_environment() described above>>> 
>> >>> response.context['latest_question_list'][> >>> Beatle?>] *Seeing What's up? here too*
>>
>>
>> Instead of getting '\n\n\nNo polls are available.\n\n' , the 
>> What's up poll is coming up i.e. b'r\n\t\r\n\t\r\n\t\t> href="/polls/1/">What'se up?\r\n\t\r\n\t\r\n? The rest of 
>> the code works fine as in adding the Beatles question but the What's up? 
>> question is also coming up along with the Beatles question. Is this ok? Any 
>> help would be greatly appreciated.
>>
>> Thanks,
>>
>> Gavin
>>
>>  -- 
>> 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 .
>> To post to this group, send email to django...@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/fc23070f-8f90-4c4c-925a-94c24d3ee8bf%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/fc23070f-8f90-4c4c-925a-94c24d3ee8bf%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/24834d06-e86a-4221-af71-5a250715076d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing your first Django app, part 5 Testing

2015-02-21 Thread Gavin Patrick McCoy
Ok. I get you. Thanks very much!

On Saturday, 21 February 2015 11:56:50 UTC, Daniel Roseman wrote:
>
> You're doing this in the shell, which uses your devv database in which you 
> have obviously defined a poll already. 
>
> The docs are taking about running this in a unit test, which would create 
> a blank db without any polls. 
> -- 
> DR.

-- 
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/408cefd6-b563-43a6-ae3f-29554e8b17cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.