On Feb 25, 2011, at 1:25 PM, DenesL wrote:
> 
> 
> The problem is checking against all dates already in the DB.
> To avoid that I would have another table with the max(to_dates) and
> min(from_dates) of all DB values, those will be updated with each new
> insert if required.
> 
> Why those values? to avoid any overlaps, then your new values must be
> such that
> to_date < min(from_dates) and from_date > max(to_dates)
> 
> plus the obvious
> from_date <= to_date
> 
> You can compare datetime.date objects with the regular comparison
> operators, e.g.
> date1 < date2

I was thinking something like this. IS_NOT_IN_DB has this code:

        field = self.dbset.db[tablename][fieldname]
        rows = self.dbset(field == value).select(limitby=(0, 1))

The range version (oversimplified, but you get the idea):

        field1 = self.dbset.db[tablename][field1name]
        field2 = self.dbset.db[tablename][field2name]
        rows = self.dbset(value1 < field2 & value2 > field1).select(limitby=(0, 
1))

I'm not sure I have the DAL syntax right, and the tests might want to include 
equality.

> 
> 
> On Feb 25, 3:00 pm, Jonathan Lundell <[email protected]> wrote:
>> On Feb 25, 2011, at 11:23 AM, greenpoise wrote:
>> 
>> 
>> 
>>> exactly, no overlapping date ranges
>> 
>> If I were doing it, I think I'd start with a (renamed) copy of 
>> gluon.validators.IS_NOT_IN_DB in my model file, and change it to do a range 
>> check on two fields, instead of an equality check on one.
>> 
>> I'm sort of fuzzy on how you do date comparisons, but presumably there's a 
>> way.
>> 
>> 
>> 
>>> On Feb 25, 11:14 am, Jonathan Lundell <[email protected]> wrote:
>>>> On Feb 25, 2011, at 11:01 AM, greenpoise wrote:
>> 
>>>>> How could I combine these two? I have a table that accepts two dates.
>>>>> I would not like duplicates between in those entry dates.
>> 
>>>>> Basically a From Date and a To Date
>> 
>>>> So the restriction is essentially: no overlapping date ranges in the 
>>>> database?
>> 
>>>>> Thanks
>> 
>>>>> Dan
>> 
>> 


Reply via email to