Created
April 30, 2018 11:12
-
-
Save BuildWithLal/843926332eb7a41bc2fcda744197eece to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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