aboutsummaryrefslogtreecommitdiffstats
path: root/97suifangqa/apps/info/models.py
diff options
context:
space:
mode:
authorAlvin Li <liweitianux@gmail.com>2013-08-13 14:13:24 +0800
committerAlvin Li <liweitianux@gmail.com>2013-08-13 14:13:24 +0800
commit9636d4a6767f49384d5c386bc3f1142c88b90613 (patch)
tree3a70f6d9e4be1791d36c87cc7cbfd1d5aa2b39dd /97suifangqa/apps/info/models.py
parent9383d9a8a5988d071766c3d08a5c946e9c5b02ae (diff)
download97dev-9636d4a6767f49384d5c386bc3f1142c88b90613.tar.bz2
cloned from 'bitbucket', 2013/08/13
Diffstat (limited to '97suifangqa/apps/info/models.py')
-rw-r--r--97suifangqa/apps/info/models.py119
1 files changed, 119 insertions, 0 deletions
diff --git a/97suifangqa/apps/info/models.py b/97suifangqa/apps/info/models.py
new file mode 100644
index 0000000..3bb1203
--- /dev/null
+++ b/97suifangqa/apps/info/models.py
@@ -0,0 +1,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,
+ ])