Aggregating distinct across OneToMany relationships using ORM

9 views
Skip to first unread message

Stephen

unread,
Jan 5, 2020, 9:14:01 AM1/5/20
to django...@googlegroups.com
Hi all,

have two Django models; MonitoringPeriod and AssignmentPeriod. Both models have start_date and end_date fields. A MonitoringPeriod can be covered by one or more AssignmentPeriod instances, which may or may not cover the entire range defined by the start and end of the MonitoringPeriod, and may or may not overlap. A MonitoringPeriod would be classed as "fully covered" if all distinct dates between its start_date and end_date are included in the set of dates specified by its related AssignmentPeriods.This is somewhat trivial to define in raw SQL but I'd prefer to do it in the ORM query setting - any ideas?

More details and class definitions, as well as raw SQL are available here:

Many thanks in advance for any guidance!

S


Reply all
Reply to author
Forward
0 new messages