from django.db import models
from django_extensions.db.models import TitleSlugDescriptionModel

# Create your models here.

class RequestedModel(models.Model):
    requested = models.DateTimeField(help_text="When the data was requested")
    
    class Meta:
        abstract = True

class RatedModel(models.Model):
    rating = models.PositiveIntegerField(help_text="The rank of a model in a set")

    class Meta:
        abstract = True

class SourceModel(TitleSlugDescriptionModel):
    url = models.URLField(help_text="The url representing the source of a model")

    class Meta:
        abstract = True





class TrendSource(SourceModel):
    pass

class Trend(RequestedModel):
    source = models.ForeignKey('TrendSource', help_text="The service that provided this set of topics")

class Topic(RatedModel):
    trend = models.ForeignKey('Trend', help_text="The set that this Topic was found in")
    term = models.CharField(max_length = 255, help_text="The term to be searched for")

class SearchSource(SourceModel):
    pass

class SearchPage(RequestedModel):
    source = models.ForeignKey('SearchSource', help_text="The service that provided this set of search results")
    topic = models.ForeignKey('Topic', help_text="The topic that was searched")
    
class SearchResult(RatedModel):
    page = models.ForeignKey('SearchPage')
    url = models.URLField(help_text="The URL to be scanned for malware")

@@ -121,21 +121,49 @@
 e.%0A%0A
-class Request
+%22%22%22%0Aabstract models.%0A%22%22%22%0A%0A%0Aclass Discover
 edMo
@@ -185,23 +185,24 @@
 l):%0A    
-request
+discover
 ed = mod
@@ -243,187 +243,27 @@
 the 
-data
+item
  was 
-requested%22)%0A    %0A    class Meta:%0A        abstract = True%0A%0Aclass RatedModel(models.Model):%0A    rating = models.PositiveIntegerField(help_text=%22The rank of a model in a set
+discovered
 %22)%0A%0A
@@ -303,16 +303,17 @@
 = True%0A%0A
+%0A
 class So
@@ -478,477 +478,464 @@
 ue%0A%0A
-%0A%0A%0A%0Aclass TrendSource(SourceModel):%0A    pass%0A%0Aclass Trend(RequestedModel):%0A    source = models.ForeignKey('TrendSource', help_text=%22The service that provided this set of topics%22)%0A%0Aclass Topic(RatedModel):%0A    trend = models.ForeignKey('Trend', help_text=%22The set that this Topic was found in%22)%0A    term = models.CharField(max_length = 255, help_text=%22The term to be searched for
+%22%22%22%0Aconcrete models%0A%22%22%22%0A%0A%0Aclass TopicSet(DiscoveredModel):%0A    source = models.CharField(max_length=255)%0A%0A%0Aclass Topic(models.Model):%0A    %22%22%22%0A    A particular trending item. Eg %22Hail Obama%22, %22#8ReasonsWhyImOnTwitter%22%0A    %22%22%22%0A    topicset = models.ForeignKey(%22TopicSet%22)%0A%0A%0Aclass Search(DiscoveredModel):%0A    source = models.CharField(max_length=255)%0A    topic = models.ForeignKey(%22Topic
 %22)%0A%0A
+%0A
 class 
-SearchSource(SourceModel):%0A    pass%0A%0Aclass SearchPage(RequestedModel):
+Result(models.Model):%0A    url = models.URLField()
 %0A    s
-ource
+earch
  = m
@@ -955,199 +955,167 @@
 Key(
-'
+%22
 Search
-Source', help_text=%22The service that provided this set of search results%22)%0A    topic = models.ForeignKey('Topic', help_text=%22The topic that was searched%22)%0A    %0Aclass SearchResult(Rated
+%22)%0A%0A%0Aclass MalwareReport(models.Model):%0A    result = models.ForeignKey(%22Result%22)%0A    reporter = models.CharField(max_length=255)%0A%0A%0Aclass Opinion(models.
 Mode
@@ -1126,11 +1126,11 @@
     
-pag
+typ
 e = 
@@ -1140,102 +1140,99 @@
 els.
-ForeignKey('SearchPage')%0A    url = models.URLField(help_text=%22The URL to be scanned for malware%22
+CharField(max_length=255)%0A    confidence = models.DecimalField(max_digits=2, decimal_places=1
 )%0A

change schema to match report json schema