-
Notifications
You must be signed in to change notification settings - Fork 4
/
models.py
79 lines (59 loc) · 2.87 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
from django.db import models
from tag_sentenze.models import Judgment, Task
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
# create a custom user model
class Profile(models.Model):
user = models.OneToOneField(
User, on_delete=models.CASCADE, primary_key=True)
# many to many relationship between a Users and Judgments through Tagging
taggings = models.ManyToManyField(
Judgment, blank=True, through='users.Tagging')
def __str__(self):
return self.user.username+"'s Profile"
# table implementing the M2M relationship between Judgment and Profile
class Tagging(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE)
judgment = models.ForeignKey(Judgment, on_delete=models.CASCADE)
token_manager = models.TextField(blank=True)
arguments_graph = models.TextField(blank=True, null=True)
relations_graph = models.TextField(blank=True, null=True)
comments = models.TextField(blank=True, null=True)
xml_text = models.TextField(blank=True)
completed = models.BooleanField(default=False)
class Meta:
unique_together = [['profile', 'judgment']]
def __str__(self):
return str(self.profile) + " tagging " + str(self.judgment)
# table implementing the M2M relationship between Judgment, User and Collection
class TaggingTask(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
judgment = models.ForeignKey(Judgment, on_delete=models.CASCADE)
token_manager = models.TextField(blank=True)
arguments_graph = models.TextField(blank=True, null=True)
relations_graph = models.TextField(blank=True, null=True)
comments = models.TextField(blank=True, null=True)
xml_text = models.TextField(blank=True)
completed = models.BooleanField(default=False)
class Meta:
unique_together = [['task', 'user', 'judgment']]
def __str__(self):
return str(self.user) + " tagging " + str(self.judgment) + " from " + str(self.task)
# class UserTasksSynonyms(models.Model):
# user_task = models.ManyToManyField(User, through='UserTasks')
# table implementing the M2M relationship between User and Collection
'''class UserTasks(models.Model):
#user_task = models.ForeignKey(UserTasksSynonyms, on_delete=models.CASCADE)
collection = models.OneToOneField(Collection, on_delete=models.CASCADE , primary_key=True)
user = models.ManyToManyField(to=User, blank=True)
#class Meta:
# unique_together = [['collection', 'user']]
def __str__(self):
return str(self.user) + " perform " + str(self.collection)'''
@receiver(post_save, sender=User)
def update_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
instance.profile.save()