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")

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

# Create your models here.

"""
abstract models.
"""


class DiscoveredModel(models.Model):
    discovered = models.DateTimeField(help_text="When the item was discovered")

    class Meta:
        abstract = True


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

    class Meta:
        abstract = True

"""
concrete models
"""


class TopicSet(DiscoveredModel):
    source = models.CharField(max_length=255)


class Topic(models.Model):
    """
    A particular trending item. Eg "Hail Obama", "#8ReasonsWhyImOnTwitter"
    """
    topicset = models.ForeignKey("TopicSet")


class Search(DiscoveredModel):
    source = models.CharField(max_length=255)
    topic = models.ForeignKey("Topic")


class Result(models.Model):
    url = models.URLField()
    search = models.ForeignKey("Search")


class MalwareReport(models.Model):
    result = models.ForeignKey("Result")
    reporter = models.CharField(max_length=255)


class Opinion(models.Model):
    type = models.CharField(max_length=255)
    confidence = models.DecimalField(max_digits=2, decimal_places=1)

change schema to match report json schema