Skip to content

Instantly share code, notes, and snippets.

@BuildWithLal
Created April 30, 2018 11:12
Show Gist options
  • Save BuildWithLal/843926332eb7a41bc2fcda744197eece to your computer and use it in GitHub Desktop.
Save BuildWithLal/843926332eb7a41bc2fcda744197eece to your computer and use it in GitHub Desktop.
user/models.py
from mongoengine import EmbeddedDocument, Document, CASCADE
from mongoengine import fields
import binascii
import os
from django.utils import timezone
class Token(EmbeddedDocument):
key = fields.StringField(max_length=44)
created = fields.DateTimeField()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not self.key:
self.key = self._generate_key()
@staticmethod
def _generate_key():
return binascii.hexlify(os.urandom(22)).decode()
def __unicode__(self):
return self.key
class SessionHistory(Document):
start_datetime = fields.DateTimeField(default=timezone.now)
end_datetime = fields.DateTimeField(default=timezone.now)
data_usage = fields.StringField()
voucher = fields.ReferenceField('captive_portal.Voucher', reverse_delete_rule=CASCADE)
device = fields.ReferenceField('configuration.Device', reverse_delete_rule=CASCADE)
user = fields.ReferenceField('configuration.User', reverse_delete_rule=CASCADE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment