from django.db import models
from base.models import Project


class DataModel(models.Model):
    name = models.CharField(max_length=64)
    project = models.ForeignKey(Project)

    def __str__(self):
        return self.name


class Crawl(models.Model):
    name = models.CharField(max_length=64)
    slug = models.CharField(max_length=64)
    description = models.TextField()
    crawler = models.CharField(max_length=64)
    status = models.CharField(max_length=64)
    config = models.CharField(max_length=64)
    seeds_list = models.CharField(max_length=64)
    pages_crawled = models.BigIntegerField()
    harvest_rate = models.FloatField()
    project = models.ForeignKey(Project)
    data_model = models.ForeignKey(DataModel)

    def __str__(self):
        return self.name

    def save(self, *args, **kwargs):
        if not self.id:
            # Newly created object, so save to get self.id
            super(Crawl, self).save(*args, **kwargs)
        self.slug = '%i-%s' % (
            self.id, slugify(self.name)
        )
        super(Crawl, self).save(*args, **kwargs)


class DataSource(models.Model):
    name = models.CharField(max_length=64)
    data_uri = models.CharField(max_length=200)
    description = models.TextField()
    project = models.ForeignKey(Project)
    crawl = models.ForeignKey(Crawl)

    def __str__(self):
        return self.name

@@ -54,16 +54,54 @@
 Project%0A
+from django.utils.text import slugify%0A
 %0A%0Aclass 
@@ -634,24 +634,33 @@
 ntegerField(
+default=0
 )%0A    harves
@@ -682,24 +682,33 @@
 .FloatField(
+default=0
 )%0A    projec
@@ -883,188 +883,19 @@
     
-if not self.id:%0A            # Newly created object, so save to get self.id%0A            super(Crawl, self).save(*args, **kwargs)%0A        self.slug = '%25i-%25s' %25 (%0A            self.id,
+self.slug =
  slu
@@ -914,18 +914,8 @@
 me)%0A
-        )%0A
     

clean slugify