from datetime import timedelta
#need a many-to-many relational table for user InjectExtension relationship
class InjectExtension(db.Model):
id = db.Column(db.Integer, primary_key=True)
inject_id = db.Column(db.Integer, db.ForeignKey('inject.id'), nullable=False)
duration = db.Column(db.Integer, nullable=False) #in minutes
start_time = db.Column(db.DateTime, default=datetime.now(), nullable=False)
@hybrid_property
def has_ended(self):
if datetime.now() > self.start_time + timedelta(minutes=self.duration):
return True
return True
class User(db.Model):
...
extensions = db.relationship('InjectExtension', lazy='dynamic', backref='teams')
class Inject(db.Model):
...
extensions = db.relationship('InjectExtension', lazy='dynamic', backref='inject')
injects.py:
extensions = [x for x in inject.extensions if g.user == x.user and not x.has_ended]
#if the extensions list is not empty then there is a valid extension for the current inject and the team should be allowed to submit, I guess this is the most elegant way to do this...
admin.py
class InjectExtensionAdmin(WhiteTeamModelView):
form_args = {"duration": {"label": "Duration (in minutes)"}}
Need db delete after implementation.
This SHOULD be implemented as one-to-many on inject-to-extensions and many-to-many on user-to-extensions. I can do that I think.
models.py:
injects.py:
admin.py
Need db delete after implementation.
This SHOULD be implemented as one-to-many on inject-to-extensions and many-to-many on user-to-extensions. I can do that I think.