Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8767351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:47:16+00:00 2026-06-13T16:47:16+00:00

Hi I have a model like so: from datetime import datetime class Project(models.Model): created

  • 0

Hi I have a model like so:

from datetime import datetime


class Project(models.Model):
    created = models.DateTimeField(editable=False)
    updated = models.DateTimeField(editable=False)
    product = models.ForeignKey('tool.product')
    module = models.ForeignKey('tool.module')
    model = models.ForeignKey('tool.model')
    zipcode = models.IntegerField(max_length=5)

    def save(self, **kwargs):
        if not self.id:
            self.created = datetime.now()
        self.updated = datetime.now()
        super(Project, self).save()

    def __unicode__(self):
        return self.id

However when I try to save a project I get:

coercing to Unicode: need string or buffer, long found

and from the runserver:

RuntimeWarning: DateTimeField received a naive datetime (2012-10-31 14:45:36.611622) while time zone support is active.

I’m not sure exactly what the problem is here but I’m assuming it has something to do with timezone getting in the way of saving the DateTimeField.

Any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:47:18+00:00Added an answer on June 13, 2026 at 4:47 pm

    First of all DateTimeField supports auto updating like this:

    created = models.DateTimeField(editable=False, auto_now_add=True) # Only on creation
    updated = models.DateTimeField(editable=False, auto_now=True)     # On every save
    

    Secondly the RuntimeWarning you get, means that you have enabled in your
    settings.py timezone aware datetime objects e.g you will see the following:

    USE_TZ = True
    

    When you do that, you have to treat datetime objects differently, you have to pass
    explicitly a tzinfo value.

    # install the `pytz` module through pip or whatnot
    from pytz import timezone
    import datetime
    from django.utils.timezone import utc
    
    now = datetime.datetime.utcnow().replace(tzinfo=utc)
    
    # To show the time in Greece
    athens = timezone('Europe/Athens')
    print now.astimezone(athens)
    

    For more info see the django docs and the pytz docs.

    About the coercing to Unicode: error, try doing this:

    def __unicode__(self):
        return unicode(self.id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following Event model: from django.db import models import datetime class
I have a model that looks like this: class Item(models.Model): ... publish_date = models.DateTimeField(default=datetime.datetime.now)
i've a problem with my tabularinline field. I have model like this class Product(models.Model):
I've got a simple User model, defined like so: # models.py from datetime import
I have a form like so: from django import forms from django.contrib.auth.models import User
I have a model like: CAMPAIGN_TYPES = ( ('email','Email'), ('display','Display'), ('search','Search'), ) class Campaign(models.Model):
I have a model like this defined... public class Product{ private long timestamp; //
Let's say I have: class Like(db.Model): user = db.ReferenceProperty(User,collection_name='likes') photo = db.ReferenceProperty(Photo,collection_name='likes_received') created =
I have a model class like this: namespace Models { public struct Localization {
I have a models.py like so: from django.db import models from django.contrib.auth.models import User

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.