forked from fossasia/open-event-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccess_code.py
More file actions
42 lines (35 loc) · 1.58 KB
/
access_code.py
File metadata and controls
42 lines (35 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from dataclasses import dataclass
from datetime import datetime
from sqlalchemy.sql import func
from app.models import db
from app.models.base import SoftDeletionModel
@dataclass(init=False, unsafe_hash=True)
class AccessCode(SoftDeletionModel):
__tablename__ = "access_codes"
id: int = db.Column(db.Integer, primary_key=True)
code: str = db.Column(db.String)
access_url: str = db.Column(db.String)
is_active: bool = db.Column(db.Boolean)
tickets_number: int = db.Column(
db.Integer
) # For event level access this holds the max. uses
min_quantity: int = db.Column(db.Integer)
max_quantity: int = db.Column(
db.Integer
) # For event level access this holds the months for which it is valid
valid_from: datetime = db.Column(db.DateTime(timezone=True), nullable=True)
valid_till: datetime = db.Column(db.DateTime(timezone=True), nullable=True)
ticket_id: int = db.Column(
db.Integer, db.ForeignKey('tickets.id', ondelete='CASCADE')
)
event_id: int = db.Column(db.Integer, db.ForeignKey('events.id', ondelete='CASCADE'))
created_at: datetime = db.Column(db.DateTime(timezone=True), default=func.now())
marketer_id: int = db.Column(
db.Integer, db.ForeignKey('users.id', ondelete='CASCADE')
)
marketer = db.relationship('User', backref='access_codes_')
ticket = db.relationship('Ticket', backref='access_code', foreign_keys=[ticket_id])
event = db.relationship('Event', backref='access_codes', foreign_keys=[event_id])
@staticmethod
def get_service_name():
return 'access_code'