class ElectionCandidatePollingStationVote(db.Model): id = db.Column(db.Integer, primary_key=True) election_candidate_id = db.Column(db.Integer, db.ForeignKey('election_candidate.id')) polling_station_id = db.Column(db.Integer, db.ForeignKey('polling_station.id')) votes = db.Column(db.Integer) polling_station = db.relationship('PollingStation', backref=db.backref( "ecpollingstationvotes", cascade="all,delete-orphan"), lazy='joined') election_candidate = db.relationship('ElectionCandidate', backref=db.backref( "ecpollingstationvotes", cascade="all,delete-orphan", lazy='joined')) def __repr__(self): pass def __json__(self): return [self.polling_station_id, self.electioncandidate, self.votes]
class PollingStationRegister(db.Model): id = db.Column(db.Integer, primary_key=True) election_id = db.Column(db.Integer, db.ForeignKey('election.id')) polling_station_id = db.Column(db.Integer, db.ForeignKey('polling_station.id')) number_of_registered_voters = db.Column(db.Integer) polling_station = db.relationship('PollingStation', backref=db.backref("elections_register")) election = db.relationship('Election', backref=db.backref('polling_stations_register', lazy='joined'))
class ConstituencyRegister(db.Model): id = db.Column(db.Integer, primary_key=True) election_id = db.Column(db.Integer, db.ForeignKey('election.id')) constituency_id = db.Column(db.Integer, db.ForeignKey('constituency.id')) number_of_registered_voters = db.Column(db.Integer) constituency = db.relationship('Constituency', backref=db.backref('election_registers', lazy='joined')) election = db.relationship('Election', backref=db.backref('constituencies_register', lazy='joined'))
class Constituency(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(40)) region_id = db.Column(db.Integer, db.ForeignKey('region.id')) #simple one to many relationship1 polling_stations = db.relationship('PollingStation', backref='constituency', lazy='dynamic') #many to many relationship type1 elections = db.relationship('ElectionConstituency', backref='constituency') def __repr__(self): return "<Constituence > %r" % self.name
class Region(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64)) constituencies = db.relationship('Constituency', backref='region', lazy='dynamic') code = db.Column(db.String(4)) def __repr__(self): return "<Region> %r %r" % (self.name, self.code)
class ElectionType(db.Model): id = db.Column(db.Integer, primary_key=True) type = db.Column(db.String(20), unique=True) elections = db.relationship('Election', backref=db.backref('electiontype', lazy="joined"), lazy='dynamic') def __repr__(self): return " <ElectionType> %r" % self.type
class Iteration(db.Model): id = db.Column(db.Integer, primary_key=True) description = db.Column(db.String(12)) elections = db.relationship('Election', backref="iteration", lazy='dynamic') def __repr__(self): return "<Iteration %r>" % self.description
class PollingStation(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(40)) constituency_id = db.Column(db.Integer, db.ForeignKey('constituency.id')) elections = db.relationship('ElectionPollingStation', backref='pollinstation') def __repr__(self): return "<Constituency > %r" % self.name
class Candidate(db.Model): id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(70)) last_name = db.Column(db.String(140)) avartar = db.Column(db.String(140)) #elections a candidate has participated in elections = db.relationship('ElectionCandidate', backref='candidate') def __repr__(self): return "<Candidate> %r %r" % (self.first_name, self.last_name)
class Incident(db.Model): id = db.Column(db.Integer, primary_key=True) description = db.Column(db.String(240)) election_polling_station_id = db.Column( db.Integer, db.ForeignKey('election_polling_station.id')) election_constituency_id = db.Column( db.Integer, db.ForeignKey('election_constituency.id')) status_type_id = db.Column(db.Integer, db.ForeignKey('incident_status.id')) election_polling_station = db.relationship('ElectionPollingStation', backref=db.backref( 'incidents', lazy="joined")) election_constituency = db.relationship('ElectionConstituency', backref=db.backref('incidents', )) status = db.relationship('IncidentStatus', backref="incidents") def __repr__(self): return "<Incident> %r constituency: %r status: %r, " % ( self.description, self.election_constituency, self.status)
class Party(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(45)) avartar = db.Column(db.String(70)) code = db.Column(db.String(10)) #election candidates election_candidates = db.relationship("ElectionCandidate", backref="party", lazy="dynamic") def __repr__(self): return "<Party> %r (%r)" % (self.name, self.code)
class ElectionCandidateConstituencyVote(db.Model): id = db.Column(db.Integer, primary_key=True) election_candidate_id = db.Column(db.Integer, db.ForeignKey('election_candidate.id')) constituency_id = db.Column(db.Integer, db.ForeignKey('constituency.id')) votes = db.Column(db.Integer) constituency = db.relationship('Constituency', backref=db.backref( "ecconstituencyvotes", cascade="all,delete-orphan")) election_candidate = db.relationship('ElectionCandidate', backref=db.backref( "ecconstituencyvotes", cascade="all,delete-orphan")) def __repr__(self): return "Election: %r ,Candidate %r , Constituency %r votes %r" % ( self.election_candidate.election, self.election_candidate.candidate, self.constituency, self.votes) def __json__(self): return [self.constituency, self.electioncandidate, self.votes]
class ElectionCandidate(db.Model): id = db.Column(db.Integer, primary_key=True) election_id = db.Column(db.Integer, db.ForeignKey('election.id')) candidate_id = db.Column(db.Integer, db.ForeignKey('candidate.id')) party_id = db.Column(db.Integer, db.ForeignKey('party.id')) #what the f**k is this? = elections and candidates for a particular election election = db.relationship('Election', backref="electioncandidates") def __repr__(self): return "<Election %r party: %r Election: %r>" % ( self.candidate, self.party, self.election) def __json__(self): return [self.candidate, self.election, self.party]
class ElectionConstituency(db.Model): id = db.Column(db.Integer, primary_key=True) election_id = db.Column(db.Integer, db.ForeignKey('election.id')) constituency_id = db.Column(db.Integer, db.ForeignKey('constituency.id')) number_of_registered_voters = db.Column(db.Integer) #many to many type1 election = db.relationship('Election', backref="constituency_electionconstituencies") def __repr__(self): return "<Election %r : %r Constituency: Total Registered Voters %r>" % ( self.election, self.constituency, self.number_of_registered_voters) def __json__(self): return [self.candidate, self.election, self.party]
class ElectionPollingStation(db.Model): id = db.Column(db.Integer, primary_key=True) election_id = db.Column(db.Integer, db.ForeignKey('election.id')) polling_station_id = db.Column(db.Integer, db.ForeignKey('polling_station.id')) number_of_registered_voters = db.Column(db.Integer) #what the f**k is this? = elections and candidates for a particular election election = db.relationship( 'Election', backref="pollingstation_electionpollingstations") def __repr__(self): return "<ElectionPollingStation> Election:%r : %r Polling Station: Total Registered Voters: %r>" % ( self.election, self.polling_station, self.total_registered_voters) def __json__(self): return [ self.election, self.pooling_station, self.number_of_registered_voters ]
class Role(db.Model): id = db.Column(db.Integer, primary_key=True) rolename = db.Column(db.String(64)) users = db.relationship('User', backref="role")