Source code for election_day.models.election.candidate_panachage_result

from onegov.core.orm import Base
from onegov.core.orm.mixins import TimestampMixin
from onegov.core.orm.types import UUID
from sqlalchemy import Column
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy.orm import relationship
from uuid import uuid4


from typing import TYPE_CHECKING
if TYPE_CHECKING:
    import uuid
    from onegov.election_day.models import Candidate
    from onegov.election_day.models import ElectionResult
    from onegov.election_day.models import List


[docs] class CandidatePanachageResult(Base, TimestampMixin):
[docs] __tablename__ = 'candidate_panachage_results'
#: identifies the result
[docs] id: 'Column[uuid.UUID]' = Column( UUID, # type:ignore[arg-type] primary_key=True, default=uuid4 )
#: the election result id this result belongs to
[docs] election_result_id: 'Column[uuid.UUID]' = Column( UUID, # type:ignore[arg-type] ForeignKey('election_results.id', ondelete='CASCADE'), nullable=False )
#: the election result this result belongs to
[docs] election_result: 'relationship[ElectionResult]' = relationship( 'ElectionResult', back_populates='candidate_panachage_results' )
#: the candidate id this result belongs to
[docs] target_id: 'Column[uuid.UUID]' = Column( UUID, # type:ignore[arg-type] ForeignKey('candidates.id', ondelete='CASCADE'), nullable=False )
#: the candidate this result belongs to
[docs] candidate: 'relationship[Candidate]' = relationship( 'Candidate', back_populates='panachage_results' )
#: the list id this result belongs to, empty in case of the blank list
[docs] source_id: 'Column[uuid.UUID | None]' = Column( UUID, # type:ignore[arg-type] ForeignKey('lists.id', ondelete='CASCADE'), nullable=True )
#: the list id this result belongs to, empty in case of the blank list
[docs] list: 'relationship[List] | None' = relationship( 'List', back_populates='candidate_panachage_results' )
#: the number of votes
[docs] votes: 'Column[int]' = Column(Integer, nullable=False, default=lambda: 0)