import datetime

from django.db import models
from taggit.managers import TaggableManager

import settings


class Book(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name = "books")
    idArticle = models.CharField(max_length=512, blank=True, null=True)
    title = models.CharField(max_length=512, blank=True)
    description = models.CharField(max_length=512, blank=True, null=True)
    image = models.URLField(max_length=2048, blank=True)
    date = models.DateTimeField(default=datetime.datetime.now)
    public = models.BooleanField(default=False, db_index=True)
    parent_visit = models.ForeignKey('Book', related_name = "books_copy", blank=True, null=True)
    
    def __str__(self):
        return self.title

class Slide(models.Model):
    book = models.ForeignKey(Book, related_name = "slides")
    idStop = models.CharField(max_length=512, blank=True)
    idInventory = models.CharField(max_length=512, blank=True)
    title = models.CharField(max_length=512, blank=True)
    description = models.CharField(max_length=1024, blank=True)
    image = models.URLField(max_length=2048, blank=True)
    date = models.DateTimeField(default=datetime.datetime.now)
    favorite = models.BooleanField(default=False, db_index=True)
    tags = TaggableManager(blank=True)
    
    def __str__(self):
        return self.idStop
    
    class Meta:
        order_with_respect_to = 'book'