aboutsummaryrefslogtreecommitdiffstats
path: root/97suifangqa/apps/info/models.py
blob: 3bb1203065ecc09b0b37abb4fe117c65fbc2eaa3 (plain)
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
# -*- coding: utf-8 -*-
from django.db import models
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic

# Create your models here.

class KeyWord(models.Model):

    content           = models.CharField(u"内容", max_length=200)
    description       = models.TextField(u"描述", blank=True)
    categoryid        = models.IntegerField(u"分类编号", null=True, blank=True)        #TODO:弄清这里的详细意义
    standard_judge    = models.BooleanField(u"是否为标准关键词", default=False)
    created_at        = models.DateTimeField(auto_now_add=True, verbose_name = u"创建时间")
    user              = models.ForeignKey(User, verbose_name=u"用户", related_name="keywords", null=True, blank=True)

    content_type      = models.ForeignKey(ContentType, null=True, blank=True)                                #将KeyWord作为GFK
    object_id         = models.PositiveIntegerField(null=True, blank=True)
    content_object    = generic.GenericForeignKey("content_type", "object_id")


    class Meta:
        verbose_name_plural = u"关键词"

    def __unicode__(self):
        return "< KeyWord: %s >" % self.content


# Query {{{
class Query(models.Model):

    content        = models.CharField(u"内容", max_length=500)
    level          = models.PositiveIntegerField(u"级数",default=1)
    categoryid     = models.IntegerField(u"分类编号", null=True, blank=True, default=1)        #TODO:弄清这里的详细意义
    created_at     = models.DateTimeField(auto_now_add=True, verbose_name = u"创建时间")
    standard_judge = models.BooleanField(u"是否为标准问题", default=False)
    user           = models.ForeignKey(User, verbose_name=u"用户", related_name="querys")

    content_type   = models.ForeignKey(ContentType, null=True, blank=True)                                #将Query作为GFK
    object_id      = models.PositiveIntegerField(null=True, blank=True)
    content_object = generic.GenericForeignKey("content_type", "object_id")


    class Meta:
        verbose_name_plural = u"问题"

    def __unicode__(self):
        return "< Query: %s >" % self.content

    def show(self):
        """
        used in 'search/search.html'
        to show search result
        """
        return self.__unicode__()
# }}}


class WordWordRelation(models.Model):

    value = models.FloatField(u"关联度")
    word1 = models.ForeignKey("KeyWord", verbose_name=u"关键词1", related_name="relations_with_other_words_as_primary", null=True, blank=True)
    word2 = models.ForeignKey("KeyWord", verbose_name=u"关键词2", related_name="relations_with_other_words_as_deputy", null=True, blank=True)

    class Meta:
        verbose_name_plural = u"关键词与关键词的关系"

    def __unicode__(self):
        return "< WordWordRelation: (%s, %s) >" % (self.word1.content, self.word2.content)


class QueryQueryRelation(models.Model):

    value  = models.FloatField(u"关联度")
    query1 = models.ForeignKey("Query", verbose_name=u"问题1", related_name="relations_with_other_querys_as_primary", null=True, blank=True)
    query2 = models.ForeignKey("Query", verbose_name=u"问题2", related_name="relations_with_other_querys_as_deputy", null=True, blank=True)

    class Meta:
        verbose_name_plural = u"问题与问题的关系"

    def __unicode__(self):
        return "< QueryQueryRelation: (%s, %s) >" % (self.query1.content, self.query2.content)


class WordQueryRelation(models.Model):

    value  = models.FloatField(u"关联度")
    word   = models.ForeignKey("KeyWord", verbose_name=u"关键词", related_name="relations_with_querys", null=True, blank=True)
    query2 = models.ForeignKey("Query", verbose_name=u"问题", related_name="relations_with_words", null=True, blank=True)

    class Meta:
        verbose_name_plural = u"关键词与问题的关系"

    def __unicode__(self):
        return "< WordQueryRelation: (%s, %s) >" % (self.word.content, self.query.content)
    

class BlogQueryRelation(models.Model):

    value = models.FloatField(u"关联度")
    blog  = models.ForeignKey("sciblog.SciBlog", verbose_name=u"文章", related_name="relations_with_querys", null=True, blank=True)
    query = models.ForeignKey("Query", verbose_name=u"问题", related_name="relations_with_blogs", null=True, blank=True)

    class Meta:
        verbose_name_plural = u"文章与问题的关系"

    def __unicode__(self):
        return "< BlogRelation: (%s, %s) >" % (self.blog.title, self.query.content)


admin.site.register([
                     KeyWord,
                     Query,
                     WordWordRelation,
                     WordQueryRelation,
                     BlogQueryRelation,
                    ])