class Maraude(models.Model): date = models.DateField(verbose_name='Date de maraude', ) description = models.CharField(max_length=2000, blank=True, null=True) heure_debut = models.CharField(max_length=7, blank=True, null=True) heure_fin = models.CharField(max_length=7, blank=True, null=True) adresse = models.CharField(max_length=2000, blank=True, null=True) association = models.ForeignKey(Association, default="", on_delete=models.CASCADE, related_name='my_maraude') arrondissement = models.ForeignKey(Arrondissement, default="", on_delete=models.CASCADE, blank=True, null=True) produit = models.ManyToManyField(Product, blank=True, related_name='maraude_product') benevole = models.ManyToManyField(Benevole, blank=True, related_name='maraude_benevole') def __str__(self): return str(self.date) + " " + str(self.association)
class Knowledge(models.Model): subject = models.CharField(max_length=255) source = models.ForeignKey('Source', related_name='knowledge') author = models.ForeignKey('users.KUser', related_name='knowledge') summary = models.CharField(max_length=255, blank=True, null=True) gainWay = models.TextField(blank=True, null=True) access = models.IntegerField(default=0) createDate = models.DateTimeField(default=datetime.now) content = models.TextField(blank=True, null=True) file = models.FileField(blank=True, null=True, upload_to=knowledge_file_name) def __str__(self): return '' + self.subject def presentation(self): return self.subject def rate(self, kuser, vote): try: rate = Rate.objects.get(knowledge=self, voter=kuser) except: rate = Rate() rate.knowledge = self rate.voter = kuser rate.up = vote rate.save() @staticmethod def kdelete(id): print('remove knowledge :' + repr(id)) Knowledge.objects.filter(pk=id).delete()
class Comment(models.Model): author = models.ForeignKey('users.KUser', related_name='comments') knowledge = models.ForeignKey('Knowledge', related_name='comments') text = models.TextField() date = models.DateTimeField(default=datetime.now) def __str__(self): return 'comment: ' + self.author.user.username + ' on ' + self.knowledge.subject
class Comment(models.Model): CommentID = models.AutoField(primary_key=True) RoadQuery = models.ForeignKey(RoadQuery, on_delete=models.PROTECT, related_name='Comment_RoadQuery') User = models.ForeignKey(UserAccount, on_delete=models.PROTECT, related_name='Comment_User') StarAmount = models.IntegerField(default=1, validators=[MaxValueValidator(5), MinValueValidator(-5)]) CommentContent = models.CharField(max_length=200) CreateDate = models.DateField() def __str__(self): return self.RoadQuery.RoadQueryName + ':' + str(self.StarAmount)
class Rate(models.Model): up = models.BooleanField(default=True) voter = models.ForeignKey('users.KUser', related_name='rates') knowledge = models.ForeignKey('Knowledge', related_name='rates') class Meta: unique_together = ['voter', 'knowledge'] def __str__(self): return str(self.knowledge) + ' vote ' + ( 'up' if self.up else 'down') + ' by ' + str(self.voter)
class TileBet(models.Model): user = models.ForeignKey(User) cell = models.ForeignKey(TileCell) no_of_tickets = models.PositiveIntegerField() def save(self, *args, **kwargs): if self.pk is None: self.cell.total_bets += self.no_of_tickets self.cell.save() cost_of_tickets = self.no_of_tickets * self.cell.game.ticket_cost profile = self.user.profile profile.points -= cost_of_tickets profile.save() return super(TileBet, self).save(*args, **kwargs)
class CardBet(models.Model): user = models.ForeignKey(User) cell = models.ForeignKey(CardCell) no_of_tickets = models.PositiveIntegerField() def save(self, *args, **kwargs): if self.pk is None: self.cell.total_bets += self.no_of_tickets self.cell.save() cost_of_tickets = self.no_of_tickets * self.cell.game.ticket_cost profile = self.user.profile profile.points -= cost_of_tickets profile.save() Transaction.objects.create(user=self.user, amount=-1 * cost_of_tickets) return super(CardBet, self).save(*args, **kwargs)
class Tag(models.Model): ktype = models.ForeignKey('TagType', related_name='tags') knowledge = models.ForeignKey('Knowledge', related_name='tags') class Meta: unique_together = ['ktype', 'knowledge'] def __str__(self): return 'Tag: (' + self.ktype.name + ') -> ' + self.knowledge.subject def abuse_presentation(self): return 'برچسب: ' + self.ktype.name + '-' + self.knowledge.subject @staticmethod def kdelete(id): print('remove tag :' + repr(id)) Tag.objects.filter(pk=id).delete()
class UserFavorite(models.Model): """用户收藏模型""" user = models.ForeignKey(UserProfile, verbose_name='用户') fav_id = models.IntegerField(default=0, verbose_name='数据id') fav_type = models.CharField(choices=(('topic', 'topic'), ('node', 'node'), ('user', 'user')), max_length=10, verbose_name='收藏类型') add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')
class InterknowledgeRelationship(models.Model): ktype = models.ForeignKey('InterknowledgeRelationshipType', related_name='relations') fromKnowledge = models.ForeignKey('Knowledge', related_name='relationToKnowledge') toKnowledge = models.ForeignKey('Knowledge', related_name='relationFromKnowledge') class Meta: unique_together = ['ktype', 'fromKnowledge', 'toKnowledge'] def __str__(self): return 'InterknowledgeRelationship: (' +self.ktype.name + '( '\ + self.fromKnowledge.subject + ' -> ' + self.toKnowledge.subject + ' )' def abuse_presentation(self): return 'رابطه: ' + self.ktype.name + ' از ' + self.fromKnowledge.subject + ' به ' + self.toKnowledge.subject @staticmethod def kdelete(id): print('remove relation :' + repr(id)) InterknowledgeRelationship.objects.filter(pk=id).delete()
class CardCell(models.Model): SUITS = (("C", "Clubs"), ("S", "Spades"), ("D", "Diamonds"), ("H", "Hearts")) VALUES = (("J", "Jack"), ("Q", "Queen"), ("K", "King")) GROUPS = (("A", "A"), ("B", "B"), ("C", "C")) game = models.ForeignKey(Cards, related_name="cells") suit = models.CharField(max_length=1, choices=SUITS) value = models.CharField(max_length=1, choices=VALUES) group = models.CharField(max_length=1, choices=GROUPS) total_bets = models.PositiveIntegerField(default=0) winner = models.BooleanField(default=False) class Meta: unique_together = ("game", "suit", "value", "group")
class RoadQuery(models.Model): RoadQueryID = models.AutoField(primary_key=True) RoadQueryName = models.CharField(max_length=50) RoadQueryAddress = models.CharField(max_length=50) RoadQueryPicture = models.CharField(max_length=100, blank=True) Classify = models.ManyToManyField(Classify) Introduction = models.TextField() Star = models.IntegerField(default=0) OpenTime = models.CharField(max_length=50) Latitude = models.CharField(max_length=30) Longitude = models.CharField(max_length=30) CreateUser = models.ForeignKey(UserAccount, on_delete=models.PROTECT, related_name='RoadQuery_CreateUser') CreateDate = models.DateTimeField() ModifyDate = models.DateTimeField() def __str__(self): return self.RoadQueryName
class TileCell(models.Model): SUITS = ( ("A", "A"), ("B", "B"), ) VALUES = ( ("1", "1"), ("2", "2"), ("3", "3"), ("4", "4"), ("5", "5"), ) GROUPS = (("A", "A"), ("B", "B"), ("C", "C")) game = models.ForeignKey(Tiles, related_name="cells") suit = models.CharField(max_length=1, choices=SUITS) value = models.CharField(max_length=1, choices=VALUES) group = models.CharField(max_length=1, choices=GROUPS) total_bets = models.PositiveIntegerField(default=0) winner = models.BooleanField(default=False) class Meta: unique_together = ("game", "suit", "value", "group")
class KnowledgeUsage(models.Model): projectProces = models.ForeignKey('ProjectProces', related_name='usedIn') def __str__(self): return 'knowledge use: ' + self.author.user.username + ' used ' + self.knowledge.subject + ' in ' + self.projectProces.phase