On Wed, Sep 23, 2009 at 4:46 AM, Jim DeLaHunt <[email protected]>wrote:

>
> 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.
>
>
What you haven't shared is the code for DateTimeFieldInTZ.  It's going to be
rather hard to figure out what is going wrong without seeing that code.

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="[email protected]")
> ...
>      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'
>

The particular test that is failing here is a bit of a red herring.  It
happens to be something that attempts to validate all models in an app (or
possibly all installed apps, depending on how it's been called which I can't
tell since some of the traceback is missing).  I'd guess having a model that
contains your custom field is what is causing this, but why is pretty hard
to say without seeing the code for the custom field.

The subsequent errors here are resulting from this attempt to create a
superupser failing, so they too are not very illuminating.

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?
>
>
If you show us what is in the DateTimeFieldInTZ implementation it's much
more likely that someone will be able to help.

Karen

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

Reply via email to