diff --git a/blog/models.py b/blog/models.py index 71a8362..d9434d8 100644 --- a/blog/models.py +++ b/blog/models.py @@ -1,3 +1,47 @@ from django.db import models # Create your models here. + + +class Category(models.Model): + name = models.CharField(max_length=200, verbose_name='Nombre') + created = models.DateTimeField(auto_now_add=True, verbose_name='Fecha de creacion') + updated = models.DateTimeField(auto_now=True, verbose_name='Fecha de edicion') + + class Meta: + ordering = ['name'] + verbose_name = 'Categoria' + verbose_name_plural = 'Categorias' + + def __str__(self): + return self.name + +class Post(models.Model): + title = models.CharField(max_length=250, verbose_name='Titulo') + image = models.ImageField(upload_to='post_images/',verbose_name='Imagen') + content = models.TextField(verbose_name='Contenido') + categories = models.ManyToManyField(Category) + created = models.DateTimeField(auto_now_add=True, verbose_name='Fecha de creacion') + updated = models.DateTimeField(auto_now=True, verbose_name='Fecha de edicion') + + class Meta: + ordering = ['title'] + verbose_name = 'Publicacion' + verbose_name_plural = 'Publicaciones' + + def __str__(self): + return self.title + + +class Blog(models.Model): + posts = models.ManyToManyField(Post) + created = models.DateTimeField(auto_now_add=True, verbose_name='Fecha de creacion') + updated = models.DateTimeField(auto_now=True, verbose_name='Fecha de edicion') + + class Meta: + ordering = ['updated'] + verbose_name_plural = 'Blogs' + verbose_name = 'Blog' + + def __str__(self): + return 'Blog Numero: {}'.format(self.pk) diff --git a/indigenous_culture/models.py b/indigenous_culture/models.py index 73e4bfe..1a04401 100644 --- a/indigenous_culture/models.py +++ b/indigenous_culture/models.py @@ -1,6 +1,7 @@ from django.db import models from django.dispatch import receiver from translate.models import Dict +from blog.models import Blog from django.db.models.signals import pre_save, post_delete # Create your models here. @@ -12,6 +13,7 @@ class Culture(models.Model): image_description = models.CharField(max_length=200, verbose_name='Descripcion de imagen') description = models.TextField(verbose_name='Descripcion') dict = models.OneToOneField(Dict, on_delete=models.CASCADE, null=True, blank=True) + blog = models.OneToOneField(Blog, on_delete=models.CASCADE, null=True, blank=True) created = models.DateTimeField(auto_now_add=True, verbose_name='Fecha de creacion') updated = models.DateTimeField(auto_now=True, verbose_name='Fecha de edicion') @@ -28,6 +30,8 @@ def __str__(self): def ensure_dict_is_created(sender, instance, **kwargs): if instance.dict == None: instance.dict = Dict.objects.create() + if instance.blog == None: + instance.blog = Blog.objects.create() if 'cultura' in instance.name.lower(): instance.name = instance.name.lower().replace('cultura', '') instance.name = instance.name.capitalize() diff --git a/translate/models.py b/translate/models.py index eef3b81..401b2c7 100644 --- a/translate/models.py +++ b/translate/models.py @@ -23,3 +23,6 @@ class Meta: ordering = ['created'] verbose_name = 'Diccionario' verbose_name_plural = 'Diccionarios' + + def __str__(self): + return 'Diccionario Numero:{}'.format(self.pk) \ No newline at end of file