Hi kbnk, monoBOT,
On Sunday, 29 November 2015 19:38:41 UTC+3, monoBOT monoBOT wrote:
-- Thank you both, your answers on the spot, I have tried using the filter and it's working, I may need to delete one of the records to get this sorted, thanks again.
>>> Question.objects.filter(pub_date__year=current_year)
[<Question: What's up?>, <Question: What's up?>]
Best regards,
Ahmed Abdullah
On Sunday, 29 November 2015 19:38:41 UTC+3, monoBOT monoBOT wrote:
Hello Ahmedyou are using the get method, get can only return 1 item and its returning more than 1 in your case 2, thats the second error, but there is an import error also somewhere in your code, but the traceback you are sending is not concluyent.2015-11-29 15:11 GMT+00:00 <ahmed.ab...@gmail.com>:Hi,--I'm practicing Django v 1.8.6 (Writing your first Django app, part 1) and getting error when trying to import timezone, also I have installed pytz, when I try to use the import timezone package I'm getting ImportError.My settings.py has USE_TZ set to true by default, also, I had to change the TIME_ZONE from UTC to Asia/Bahrain but still I'm getting the below error, kindly if anyone have advice on the below error?>>> from polls.models import Question, Choice>>> Question.objects.all()[<Question: What's up?>, <Question: What's up?>]>>> Question.objects.filter(id=1)[<Question: What's up?>]>>> Question.objects.filter(id=2)[<Question: What's up?>]>>> Question.objects.filter(id=3)[]>>> Question.objects.filter(question_text__startswith=' What') [<Question: What's up?>, <Question: What's up?>]>>> from django.utils import timezone>>> current_year = timezone.now().year>>> Question.objects.get(pub_date__year=current_year) Traceback (most recent call last):File "C:\Users\abdullaha\AppData\Local\Programs\Python\ Python35\lib\site-packages\ django\core\management\ commands\shell.py", line 69, in h andleself.run_shell(shell=options['interface']) File "C:\Users\abdullaha\AppData\Local\Programs\Python\ Python35\lib\site-packages\ django\core\management\ commands\shell.py", line 61, in r un_shellraise ImportErrorImportErrorDuring handling of the above exception, another exception occurred:Traceback (most recent call last):File "<console>", line 1, in <module>File "C:\Users\abdullaha\AppData\Local\Programs\Python\ Python35\lib\site-packages\ django\db\models\manager.py", line 127, in manager_metho dreturn getattr(self.get_queryset(), name)(*args, **kwargs)File "C:\Users\abdullaha\AppData\Local\Programs\Python\ Python35\lib\site-packages\ django\db\models\query.py", line 338, in get (self.model._meta.object_name, num)polls.models.MultipleObjectsReturned: get() returned more than one Question -- it returned 2! >>>Best regards,Ahmed Abdullah
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/f6953f2e- .f9a6-46c7-aec8-f337b772fc9b% 40googlegroups.com
For more options, visit https://groups.google.com/d/optout .
--monoBOTVisite mi sitio(Visit my site): monobotsoft.es/blog/
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+unsubscribe@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/cccb90ea-cdf7-4a51-9cf0-ca9add0b4f4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment