-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
193 lines (138 loc) · 6.12 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey has `on_delete` set to the desired behavior.
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models
class Account(models.Model):
username = models.CharField(primary_key=True, max_length=20)
description = models.CharField(max_length=20, blank=True, null=True)
account_type = models.CharField(max_length=20)
class Meta:
managed = False
db_table = 'account'
class Komik(models.Model):
title = models.CharField(max_length=20)
description = models.CharField(max_length=100, blank=True, null=True)
rating = models.DecimalField(max_digits=3, decimal_places=2, blank=True, null=True)
image_url = models.CharField(max_length=100, blank=True, null=True)
class Meta:
managed = False
db_table = 'komik'
class List(models.Model):
title = models.CharField(max_length=20, blank=True, null=True)
description = models.CharField(max_length=100, blank=True, null=True)
user = models.ForeignKey(Account, models.DO_NOTHING)
list_size = models.IntegerField()
class Meta:
managed = False
db_table = 'list'
class Listrank(models.Model):
list = models.ForeignKey(List, models.DO_NOTHING)
komik = models.ForeignKey(Komik, models.DO_NOTHING)
ranking = models.IntegerField()
description = models.CharField(max_length=100, blank=True, null=True)
class Meta:
managed = False
db_table = 'listrank'
unique_together = (('list', 'ranking'),)
class Review(models.Model):
user = models.ForeignKey(Account, models.DO_NOTHING)
komik = models.ForeignKey(Komik, models.DO_NOTHING, primary_key=True)
rating = models.IntegerField(blank=True, null=True)
comment = models.CharField(max_length=100, blank=True, null=True)
class Meta:
managed = False
db_table = 'review'
unique_together = (('komik', 'user'),)
class Tag(models.Model):
name = models.CharField(unique=True, max_length=20)
description = models.CharField(max_length=100, blank=True, null=True)
class Meta:
managed = False
db_table = 'tag'
class Tags(models.Model):
tag = models.ForeignKey(Tag, models.DO_NOTHING, primary_key=True)
komik = models.ForeignKey(Komik, models.DO_NOTHING)
class Meta:
managed = False
db_table = 'tags'
unique_together = (('tag', 'komik'),)
# ---------------------------------------------------
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey has `on_delete` set to the desired behavior.
# * Remove `` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models
from django.contrib.auth.models import User
from django.dispatch import receiver
from django.db.models.signals import post_save
# account should be foreign key on delete CASCADE
class Account(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
username = models.CharField(primary_key=True, max_length=20)
description = models.CharField(max_length=500, blank=True, null=True)
account_type = models.CharField(max_length=20)
class Meta:
db_table = 'account'
@receiver(post_save, sender=User)
def update_user_account(sender, instance, created, **kwargs):
if created:
Account.objects.create(user=instance, username=instance.username)
instance.account.save()
class Tag(models.Model):
name = models.CharField(unique=True, max_length=50)
description = models.CharField(max_length=500, blank=True, null=True)
class Meta:
db_table = 'tag'
def __str__(self):
return self.name
class Komik(models.Model):
title = models.CharField(max_length=100)
description = models.CharField(max_length=500, blank=True, null=True)
rating = models.DecimalField(max_digits=3, decimal_places=2, blank=True, null=True)
image_url = models.CharField(max_length=500, blank=True, null=True)
author = models.CharField(max_length=100, null=True, blank=True)
komik_tags = models.ManyToManyField(Tag, through='Tags')
def __str__(self):
return self.title
class Meta:
db_table = 'komik'
class Tags(models.Model):
tag = models.ForeignKey(Tag, models.DO_NOTHING)
komik = models.ForeignKey(Komik, models.DO_NOTHING)
def __str__(self):
return self.komik.title + ':' + self.tag.name
class Meta:
db_table = 'tags'
unique_together = (('tag', 'komik'),)
class Review(models.Model):
user = models.ForeignKey(Account, models.DO_NOTHING)
komik = models.ForeignKey(Komik, models.DO_NOTHING)
rating = models.IntegerField(blank=True, null=True)
comment = models.CharField(max_length=500, blank=True, null=True)
class Meta:
db_table = 'review'
unique_together = (('komik', 'user'),)
class List(models.Model):
title = models.CharField(max_length=50, blank=True, null=True)
description = models.CharField(max_length=500, blank=True, null=True)
user = models.ForeignKey(Account, models.DO_NOTHING)
list_size = models.IntegerField()
list_komiks = models.ManyToManyField(Komik, through='ListRank')
class Meta:
db_table = 'list'
class ListRank(models.Model):
list = models.ForeignKey(List, models.DO_NOTHING)
komik = models.ForeignKey(Komik, models.DO_NOTHING)
ranking = models.IntegerField()
description = models.CharField(max_length=500, blank=True, null=True)
class Meta:
db_table = 'listrank'
unique_together = (('list', 'ranking'), ('list', 'komik'))
ordering =('ranking', )