-
Notifications
You must be signed in to change notification settings - Fork 3
/
models.py
97 lines (68 loc) · 2.8 KB
/
models.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import importlib
from django.contrib.auth.base_user import AbstractBaseUser
from django.db import models
from .controllers import BaseController
base = BaseController()
class User(AbstractBaseUser):
id = models.BigIntegerField(primary_key=True)
is_superuser = models.BooleanField(default=False, db_index=True)
is_staff = models.BooleanField(default=False, db_index=True)
command_count = models.IntegerField(default=0)
USERNAME_FIELD = 'id'
def get_full_name(self):
return str(self.id)
def get_short_name(self):
return str(self.id)[0:7]
def __int__(self):
return self.id
class Guild(models.Model):
# I can't normalize this any further :/
id = models.BigIntegerField(primary_key=True)
name = models.CharField(max_length=64, unique=True, db_index=True)
register_time = models.TimeField('date registered', auto_now=True)
invite_link = models.CharField(max_length=64, unique=True, db_index=True)
url = models.CharField(max_length=256, unique=True)
is_deleted = models.BooleanField(default=False)
def __int__(self):
return self.id
class Channel(models.Model):
id = models.BigIntegerField(primary_key=True)
guild = models.ForeignKey(Guild, on_delete=models.CASCADE)
def __int__(self):
return self.id
class Role(models.Model):
id = models.BigIntegerField(primary_key=True)
guild = models.ForeignKey(Guild, on_delete=models.CASCADE)
def __int__(self):
return self.id
class Member(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
guild = models.ForeignKey(Guild, on_delete=models.CASCADE)
def __int__(self):
return self.id
class Message(models.Model):
id = models.BigIntegerField(primary_key=True)
user = models.ForeignKey(User, db_index=True, on_delete=models.CASCADE)
channel = models.ForeignKey(Channel, on_delete=models.CASCADE)
content = models.TextField(max_length=2000)
clean_content = models.TextField(max_length=2000)
def __int__(self):
return self.id
class String(models.Model):
name = models.CharField(primary_key=True, max_length=64)
en_us = models.CharField(max_length=2000)
# Importing models introduced by extensions.
# Kinda hacky but there seems to be no clean way to do this.
extensions = base.get_extensions()
for extension in extensions:
try:
# mimic `from dwarf.extension.models import *`
models_module = importlib.import_module('dwarf.' + extension + '.models')
module_dict = models_module.__dict__
try:
to_import = models_module.__all__
except AttributeError:
to_import = [name for name in module_dict if not name.startswith('_')]
globals().update({name: module_dict[name] for name in to_import})
except ImportError:
pass