Django models

The data collected using the spiders needs to be stored in a database. In Django, the database tables are called models and defined in the models.py file (within the pages folder). The content of this file is as follows:

from django.db import models
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

class SearchTerm(models.Model):
    term = models.CharField(_('search'), max_length=255)
    num_reviews = models.IntegerField(null=True,default=0)
    #display term on admin panel
    def __unicode__(self):
            return self.term

class Page(models.Model):
     searchterm = models.ForeignKey(SearchTerm, related_name='pages',null=True,blank=True)
     url = models.URLField(_('url'), default='', blank=True)
 title = models.CharField(_('name'), ...

Get Machine Learning for the Web now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.