sqlalchemy.distinct.label

Here are the examples of the python api sqlalchemy.distinct.label taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

3 Source : notification_template.py
with MIT License
from OneGov

    def recipients_with_wishes(self):
        bookings = BookingCollection(self.request.session)

        if not self.period.wishlist_phase:
            return set()

        q = bookings.query().filter_by(period_id=self.period.id)
        q = q.with_entities(distinct(Booking.username).label('username'))

        return {b.username for b in q}

    def recipients_with_accepted_bookings(self):

3 Source : notification_template.py
with MIT License
from OneGov

    def recipients_with_accepted_bookings(self):
        bookings = BookingCollection(self.request.session)

        if self.period.wishlist_phase:
            return set()

        q = bookings.query().filter_by(
            period_id=self.period.id,
            state='accepted')

        q = q.with_entities(distinct(Booking.username).label('username'))

        return {b.username for b in q}

    def recipients_which_are_active_organisers(self):

3 Source : notification_template.py
with MIT License
from OneGov

    def recipients_which_are_active_organisers(self):
        occasions = OccasionCollection(self.request.session)

        q = occasions.query().filter_by(period_id=self.period.id)
        q = q.join(Activity)
        q = q.filter(Occasion.cancelled == False)

        q = q.with_entities(distinct(Activity.username).label('username'))

        return {o.username for o in q}

    def recipients_with_unpaid_bills(self):

3 Source : notification_template.py
with MIT License
from OneGov

    def recipients_by_occasion(self, occasions, include_organisers=True):
        q = self.recipients_by_occasion_query(occasions)
        q = q.with_entities(distinct(Booking.username).label('username'))

        attendees = {r.username for r in q}

        if not include_organisers:
            return attendees

        q = OccasionCollection(self.request.session).query()
        q = q.join(Activity)
        q = q.filter(Occasion.id.in_(occasions))
        q = q.with_entities(distinct(Activity.username).label('username'))

        organisers = {r.username for r in q}

        return attendees | organisers

    @property

3 Source : client_db.py
with MIT License
from zhanghe06

def get_distinct(model_class, field, *args, **kwargs):
    session = db_session_mysql()
    try:
        result = session.query(distinct(getattr(model_class, field)).label(field)).filter(*args).filter_by(**kwargs).all()
        return result
    finally:
        session.close()


def get_group(model_class, field, min_count=0, *args, **kwargs):