AssertionError in django

Kris Winiarski

I've been pulling my hair out on this one and it seems like there is a really simple solution for it but I'm too blind to see it. I've upgraded from Django 1.4.3 to Django 1.6 and ever since then I get an assertion error while trying to get DateTimeField to work.

Here's my model

class Article(models.Model):
'''Article Model'''

banner = models.ImageField(verbose_name="Banner", null=True, blank=True, upload_to='ajax_uploads/banners', max_length=300)

title = models.CharField(
    verbose_name = _(u'Title'),
    help_text = _(u' '),
    max_length = 255
)
slug = models.SlugField(
    verbose_name = _(u'Slug'),
    help_text = _(u'Uri identifier.'),
    max_length = 255
)
content_markdown = models.TextField(
    verbose_name = _(u'Content (Markup)'),
    help_text = _(u' '),
)
content_markup = models.TextField(
    verbose_name = _(u'Content (Markup)'),
    help_text = _(u' '),
)
categories = models.ManyToManyField(
    Category,
    verbose_name = _(u'Categories'),
    help_text = _(u' '),
    null = True,
    blank = True
)
date_publish = models.DateTimeField(
    default=datetime.date.today,
    verbose_name = _(u'Publish Date'),
    help_text = _(u' ')
)

class Meta:
    app_label = _(u'blog')
    verbose_name = _(u'Article')
    verbose_name_plural = (u'Articles')
    ordering = ['-date_publish']

def save(self):
    self.content_markup = markdown(self.content_markdown, ['codehilite'])
    super(Article, self).save()

def __unicode__(self):
        return '%s' % (self.title,)

views.py:

def index(request):
'''News index'''
archive_dates = Article.objects.dates('date_publish','month', order='DESC')
categories = Category.objects.all()

page = request.GET.get('page')
article_queryset = Article.objects.all()
paginator = Paginator(article_queryset, 5)

try:
    articles = paginator.page(page)
except PageNotAnInteger:
    #If page requested is not an integer, deliver first page.
    articles = paginator.page(1)
except EmptyPage:
    #If page requested is out of range, deliver last page of results.
    articles = paginator.page(paginator.num_pages)

return render(
    request,
    'blog/article/index.html',
{
    'articles' : articles,
    'archive_dates' : archive_dates,
    'categories' : categories
}
)

and template

                        <div class="8u skel-cell-important">
                                    {% for item in articles %}
                                            <!-- Content -->
                                                <article class="box is-post">
                                                    <a href="{% url "blog-article-single" slug=item.slug %}" class="image image-full"><img src="/media/{{ item.banner }}" alt="" /></a>
                                                    <header>
                                                        <h2><a href="{% url "blog-article-single" slug=item.slug %}">{{ item.title }}</a></h2>
                                                        <span class="byline">Published {{  item.date_publish|date:"j, M, Y" }}</span>
                                                    </header>
                                                    <p>
                                                        {{ item.content_markup|safe|slice:":250" }}...
                                                    </p>
                                                </article>
                                    {% endfor %}
                                        </div>

and finally error traceback:

AssertionError at /blog/

'date_publish' is a DateTimeField, not a DateField.

Request Method:     GET
Request URL:    http://localhost:8000/blog/
Django Version:     1.6.1
Exception Type:     AssertionError
Exception Value:    

'date_publish' is a DateTimeField, not a DateField.

Exception Location:     /usr/local/lib/python2.7/dist-packages/django/db/models/sql/subqueries.py in _check_field, line 258
Python Executable:  /usr/bin/python2.7
Python Version:     2.7.3
Python Path:    

['/home/user/paperpxl',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PIL',
 '/usr/lib/python2.7/dist-packages/gst-0.10',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
 '/usr/lib/python2.7/dist-packages/ubuntuone-couch',
 '/usr/lib/python2.7/dist-packages/ubuntuone-installer',
 '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']

Server time:    Thu, 19 Dec 2013 15:28:43 +0000

Any kind of help would be appreciated!

EDIT : Thanks for your help guys, I'm going back to the release notes to read through them again! I wish I had an eye for detail like you do.

Alasdair

date_publish is a DateTimeField, not a DateField. Use the datetimes() method instead of dates().

Article.objects.datetimes('date_publish', 'month', order='DESC')

See the 1.6 release notes for more details.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AssertionError - no exception supplied - django

From Dev

Django AssertionError - 302 is not 302

From Dev

AssertionError - no exception supplied - django

From Dev

Django Rest Framework - AssertionError in tests

From Dev

AssertionError at ************** in Django-Rest Framework

From Dev

Django: Testing LoginView throwing AssertionError

From Dev

Django REST - AssertionError: `fields` must be a list or tuple

From Dev

AssertionError with custom user model django-allauth

From Dev

Django pytest AssertionError: should return body unicode

From Dev

Django REST - AssertionError: `fields` must be a list or tuple

From Dev

Django: atomic(): Force transaction, raise AssertionError if already inside a transaction

From Java

How to resolve AssertionError: .accepted_renderer not set on Response in django and ajax

From Dev

Django POST Method Unit Test failing with Assertionerror 401

From Dev

Django 1.9.2 AssertionError: database connection isn't set to UTC

From Dev

Django POST Method Unit Test failing with Assertionerror 401

From Dev

django assertionerror: assert token.contents == 'endif' in template?

From Dev

Django Template getting apparent catchall error: "AssertionError at / No exception message supplied"

From Dev

Django AssertionError "sensitive_post_parameters didn't receive an HttpRequest" on add users in admin

From Dev

PowerMock AssertionError

From Dev

Python AssertionError

From Dev

AssertionError: 200 != 403

From Dev

AssertionError when using nosetests

From Dev

AssertionError: Unassigned partition

From Dev

Pip list crashes with an AssertionError

From Dev

Strange AssertionError in asyncio

From Dev

Python argparse AssertionError

From Dev

AssertionError using Basemap and Pandas

From Dev

Mocha Test Fails with AssertionError

From Dev

Junit expectMessage AssertionError

Related Related

  1. 1

    AssertionError - no exception supplied - django

  2. 2

    Django AssertionError - 302 is not 302

  3. 3

    AssertionError - no exception supplied - django

  4. 4

    Django Rest Framework - AssertionError in tests

  5. 5

    AssertionError at ************** in Django-Rest Framework

  6. 6

    Django: Testing LoginView throwing AssertionError

  7. 7

    Django REST - AssertionError: `fields` must be a list or tuple

  8. 8

    AssertionError with custom user model django-allauth

  9. 9

    Django pytest AssertionError: should return body unicode

  10. 10

    Django REST - AssertionError: `fields` must be a list or tuple

  11. 11

    Django: atomic(): Force transaction, raise AssertionError if already inside a transaction

  12. 12

    How to resolve AssertionError: .accepted_renderer not set on Response in django and ajax

  13. 13

    Django POST Method Unit Test failing with Assertionerror 401

  14. 14

    Django 1.9.2 AssertionError: database connection isn't set to UTC

  15. 15

    Django POST Method Unit Test failing with Assertionerror 401

  16. 16

    django assertionerror: assert token.contents == 'endif' in template?

  17. 17

    Django Template getting apparent catchall error: "AssertionError at / No exception message supplied"

  18. 18

    Django AssertionError "sensitive_post_parameters didn't receive an HttpRequest" on add users in admin

  19. 19

    PowerMock AssertionError

  20. 20

    Python AssertionError

  21. 21

    AssertionError: 200 != 403

  22. 22

    AssertionError when using nosetests

  23. 23

    AssertionError: Unassigned partition

  24. 24

    Pip list crashes with an AssertionError

  25. 25

    Strange AssertionError in asyncio

  26. 26

    Python argparse AssertionError

  27. 27

    AssertionError using Basemap and Pandas

  28. 28

    Mocha Test Fails with AssertionError

  29. 29

    Junit expectMessage AssertionError

HotTag

Archive