Skip to content

Commit

Permalink
Creados Modelos Y Campos Para La App Blog
Browse files Browse the repository at this point in the history
Creado un campo blog de tipo OneToOneField dentro del modelo Culture,
Creados Los Modelos Blog, Post, y Category;
Redefinicion del metodo __str__ dentro del modelo Dict,
Y Creada una senal para crear un blog automaticamente durante el
pre_save del modelo Culture.
  • Loading branch information
ChekeGT committed Sep 20, 2018
1 parent c0fd568 commit bc4c1bc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
44 changes: 44 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions indigenous_culture/models.py
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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')

Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions translate/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ class Meta:
ordering = ['created']
verbose_name = 'Diccionario'
verbose_name_plural = 'Diccionarios'

def __str__(self):
return 'Diccionario Numero:{}'.format(self.pk)

0 comments on commit bc4c1bc

Please sign in to comment.