Monday, August 30, 2010

Re: Model Validation - Prevent Datetimefield overlaps?

On Mon, Aug 30, 2010 at 10:34 PM, Victor Hooi <victorhooi@gmail.com> wrote:
Just playing around - I noticed that setting "unique=True" on a
DateTimeField() doesn't seem to work? As in, I was able to do
something like:

b1 =
BandwidthUsageEntry(start_of_usage_block=datetime.datetime(2007,05,05,12,05),
end_of_usage_block=datetime.datetime(2007,05,12,12,10),bytes_in=10,bytes_out=10)
b1.save()
b2 =
BandwidthUsageEntry(start_of_usage_block=datetime.datetime(2007,05,05,12,05),
end_of_usage_block=datetime.datetime(2007,05,12,12,10),bytes_in=20,bytes_out=20)
b2.save()

Is this expected behaviour, or do I have something wrong with my
setup?

Did you add the unique=True to the fields after you had already run syncdb to create the table?  If so, the database constraints to require the field to be unique won't be in place. (And re-running syncdb won't create the constraints either, since syncdb won't do anything for models with tables that already exist.)

Karen
--
http://tracey.org/kmt/

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment