class Gyms(models.Model): name = models.TextField() last_check_in = models.TimeStampField(default=datetime.datetime.utcnow()) location = models.TextField() class Meta: collection_name = GYM_COLLECTION
class Member(BaseModel): last_name = models.TextField() first_name = models.TextField() refresh_token = models.TextField(blank=True) access_token = models.TextField(blank=True) access_token_expiry = models.IntegerField(blank=True) @staticmethod def add(athlete, refresh_token=None, access_token=None, access_token_expiry=None): """Takes a stravalib.model.Athlete object and adds it """ m = Member.objects.create(id=athlete.id, last_name=athlete.lastname, first_name=athlete.firstname, refresh_token=refresh_token, access_token=access_token, access_token_expiry=access_token_expiry, audit_inserted=datetime.utcnow()) m.save() Handicap.add(m) Activity.add(Activity.MEMBER_CONNECTED, member_id=m.id) return m def update_handicap(self, new_handicap): Handicap.add(self, new_handicap) def jsonify(self): return { "id": self.id, "first_name": self.first_name, "last_name": self.last_name }
class Usage(models.Model): date = models.TextField() machine_id = models.TextField() name = models.TextField() times = models.ListField(default=list()) total_time = models.IntegerField(default=0) class Meta: collection_name = USAGE_COLLECTION
class Challenge(BaseModel): date_from = models.TimeStampField() date_to = models.TimeStampField() segment_id = models.IntegerField() segment_name = models.TextField() audit_inserted = models.TimeStampField(datetime.now()) @staticmethod def add(segment, year, month): """Takes a stravalib.model.Segment object and adds it as the target challenege to cover the given month of the given year""" _, end_day = calendar.monthrange(year, month) date_from = datetime.combine(date(year, month, 1), datetime.min.time()) date_to = datetime.combine(date(year, month, end_day), datetime.min.time()) c = Challenge.objects.create(segment_id=segment.id, segment_name=segment.name, date_from=date_from, date_to=date_to, audit_inserted=datetime.utcnow()) c.save() Activity.add(Activity.CHALLENGE_ADDED, challenge_id=c.id) return c def jsonify(self): return { "id": self.id, "date_from": self.date_from, "date_to": self.date_to, "segment_id": self.segment_id, "segment_name": self.segment_name }
class BaseClass(models.Model): name = models.TextField() active = models.BooleanField(column_name='is_active') list_f = models.ListField(blank=True, column_name='lista') class Meta: abstract = True collection_name = 'collection_name'
class NewBaseClass(models.Model): name = models.TextField(default='aaaaa') active = models.BooleanField(column_name='is_active', default=False) list_f = models.ListField(default=[], column_name='lista') map_f = models.MapField(default={}, column_name='mapa') class Meta: abstract = True collection_name = 'collection_name'
class Activity(BaseModel): message = models.TextField(blank=True) member_id = models.TextField(blank=True) challenge_id = models.TextField(blank=True) attempt_id = models.TextField(blank=True) MEMBER_CONNECTED = "MEMBER_CONNECTED" CHALLENGE_ADDED = "CHALLENGE_ADDED" CHALLENGE_ATTEMPTED = "CHALLENGE_ATTEMPTED" @staticmethod def add(message, member_id=None, challenge_id=None, attempt_id=None): a = Activity.objects.create(message=message, member_id=member_id, challenge_id=challenge_id, attempt_id=attempt_id, audit_inserted=datetime.utcnow()) a.save() return a
class Class(models.Model): name = models.TextField() active = models.BooleanField(column_name='is_active') list_f = models.ListField(blank=True) map_f = models.MapField(blank=True)
class TestModelClass(models.Model): name = models.TextField() age = models.IntegerField() class Meta: collection_name = 'tmc'
class TestModelClassParent(models.Model): name = models.TextField() age = models.IntegerField()
class AClass(models.Model): name = models.TextField() age = models.IntegerField() class Meta: abstract = True
class AClass(models.Model): name = models.TextField() age = models.IntegerField()
class User(models.Model): name = models.TextField()
class C(models.Model): name = models.TextField() active = models.BooleanField()
class B(models.Model): name = models.TextField()
class Room(models.Model): name = models.TextField() class Meta: collection_name = 'rooms'
class Message(models.Model): msg = models.TextField() user = models.ReferenceField(User) class Meta: collection_name = 'messages'