Hello all,

I've been hitting a small annoyance when using the RangeField classes in 
the PostgreSQL contrib modules : while the value returned by psycopg is a 
psycopg.extras.Range type, the Django documentation explicitly mentions 
using tuples when creating and updating model instances.

This means that any method or property that has to process RangeFields must 
handle both tuples and Range types, which are incompatible.

For example, here is a very simple model :

    class MyModel(models.Model):

        range = DateTimeRangeField()

        def has_started_1(self):
            return self.range.lower() <= timezone.now()

        def has_started_2(self):
            return self.range[0] <= timezone.now()

In this naïve implementation, the `has_started_1` method will crash when 
used like this :

    instance = MyModel.objects.create(range=(timezone.now(), timezone.now() 
+ timezone.timedelta(days=5))
    instance.has_started_1()  # Crash
    instance.has_started_2()  # True

...and the `has_started_2` method will crash with this :

    instance = MyModel.objects.last()
    instance.has_started_1()  # True
    instance.has_started_2()  # Crash

How should I handle that better?

Thanks for your help!
François-Xavier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/721d0534-35d4-4c8c-98af-913bcd39be56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to