heya, I have a model that contains a whole bunch of bytes in/out for datetime ranges. I.e.:
class BandwidthUsageEntry(models.Model): start_of_usage_block = models.DateTimeField() end_of_usage_block = models.DateTimeField() bytes_in = models.IntegerField() bytes_out = models.IntegerField() I need to ensure that each entry doesn't overlap with any others entries. 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? Anyhow, in terms of how to actually prevent overlaps, I assume that the best way is to use a custom model validator, and check each start/ end against a query against all the entries? (I saw this http://stackoverflow.com/questions/2243490/django-unique-time-interval-for-the-admin-panel, but it seems to be going a different way that I don't follow). How would I go about structuring this? Any particular tips here, or any algorithms that could work well? Cheers, Victor -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.