Hi, folks:

I'm new to Django. It's a very powerful system, and I appreciate the
work of the people who built it up into what I'm benefiting from.

I'm having a difficulty with a very simple app which exercises a
custom field type of mine, one which improves the time zone handling
of models.DateTimeField a little. When I put my field into my app's
model, I get an "IntegrityError: <field> may not be NULL" when I try
to save() the object. I also get a number of errors in the BASICTESTS
part of the built-in test suite. I've tried reading the docs, and
re-reading my code. I'm just not making progress. Can anyone shed some
light?

Here's my model:

from django.db import models
#from twang.workshop.utcdatetime import UTCDateTimeField   # this
errors out for me. #TODO deleteme.
from twang.workshop.datetimefieldintz import DateTimeFieldInTZ

class TwStatus(models.Model):
        id         = models.PositiveIntegerField(primary_key=True)
        created_at = DateTimeFieldInTZ()
        text       = models.CharField(max_length=200)

        def __unicode__(self):
                return unicode(type(self).__name__) +u"(" + unicode(self.id) + 
u", " + \
                                unicode(self.created_at) + u", " + 
repr(self.text) + u")"

Here's the test code which fails:

inputDict = {
                                'created_at': datetime( 2009, 6, 30, 23, 59, 
45, 0, utc ),
                                'id': 2411984892L,
                                'text': '@bowwow614 damn bow  next time  u need 
2 answer yo phone
b -4 i go ghetto on yo azz lol',
                }

S1 = models.TwStatus(**self.inputDict)
S1.save()


Here's the error message I get from the failed .save():

.... [7 levels of traceback omitted] ...
File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py",
line 193, in execute
    return Database.Cursor.execute(self, query, params)
IntegrityError: workshop_twstatus.created_at may not be NULL

What I don't get is that when I print out S1 just before the
S1.save(), I see that the created_at field does indeed have a non-null
value.

When I change the field definition from "DateTimeFieldInTZ" to
"models.DateTimeField", then the error message disappears works.

I'm testing this code by using "python manage.py test". This gives me
the failure above, and these failures in the BASICTESTS suite.

AssertionError: Failed doctest test for
django.contrib.auth.tests.__test__.BASIC_TESTS
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/contrib/auth/tests/__init__.py",
line unknown line number, in BASIC_TESTS
...
Failed example:
    call_command("createsuperuser", interactive=False, username="joe",
email="j...@somewhere.org")
...
      File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/validation.py",
line 38, in get_validation_errors
        if f.name.endswith('_'):
    AttributeError: 'NoneType' object has no attribute 'endswith'
...
Failed example:
    u = User.objects.get(username="joe")
Exception raised:
...
      File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/query.py",
line 305, in get
        % self.model._meta.object_name)
    DoesNotExist: User matching query does not exist.
...
Failed example:
    u.email
Expected:
    u'j...@somewhere.org'
Got:
    't...@example.com'
...
Failed example:
    u.password
Expected:
    u'!'
Got:
    '!'


Even if I hack the DateTimeFieldInTZ class so that each of its methods
calls the superclass and returns right away, I still get the same
error.
Any insights?

Thanks in advance for your help.
    --Jim DeLaHunt, Vancouver, Canada

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to