Creacion Blog

This commit is contained in:
jp.dev 2020-11-21 02:49:07 -03:00
parent 44aaab57ea
commit b284f796f8
10 changed files with 109 additions and 0 deletions

View File

@ -39,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'ProyectoWebApp',
'servicios',
'blog',
]
MIDDLEWARE = [

View File

16
ProyectoWeb/blog/admin.py Normal file
View File

@ -0,0 +1,16 @@
from django.contrib import admin
from .models import Categoria, Entrada
# Register your models here.
class CategoriaAdmin(admin.ModelAdmin):
readonly_fields = ('created', 'updated')
class EntradasAdmin(admin.ModelAdmin):
readonly_fields = ('created', 'updated')
admin.site.register(Categoria, CategoriaAdmin)
admin.site.register(Entrada, EntradasAdmin)

5
ProyectoWeb/blog/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class BlogConfig(AppConfig):
name = 'blog'

View File

@ -0,0 +1,47 @@
# Generated by Django 3.1.3 on 2020-11-21 05:08
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Categoria',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nombre', models.CharField(max_length=50)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now_add=True)),
],
options={
'verbose_name': 'categoria',
'verbose_name_plural': 'categorias',
},
),
migrations.CreateModel(
name='Entrada',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('titulo', models.CharField(max_length=50)),
('contenido', models.CharField(max_length=50)),
('imagen', models.ImageField(blank=True, null=True, upload_to='blog')),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now_add=True)),
('autor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('categorias', models.ManyToManyField(to='blog.Categoria')),
],
options={
'verbose_name': 'entrada',
'verbose_name_plural': 'entradas',
},
),
]

View File

View File

@ -0,0 +1,37 @@
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Categoria(models.Model):
nombre = models.CharField( max_length = 50 )
created = models.DateTimeField( auto_now_add = True)
updated = models.DateTimeField( auto_now_add = True)
class Meta:
verbose_name = 'categoria'
verbose_name_plural = 'categorias'
def __str__(self):
return self.nombre
class Entrada(models.Model):
titulo = models.CharField( max_length = 50 )
contenido = models.CharField( max_length = 50 )
autor = models.ForeignKey( User, on_delete = models.CASCADE )
categorias = models.ManyToManyField( Categoria )
imagen = models.ImageField( upload_to='blog', null=True, blank=True )
created = models.DateTimeField( auto_now_add = True)
updated = models.DateTimeField( auto_now_add = True)
class Meta:
verbose_name = 'entrada'
verbose_name_plural = 'entradas'
def __str__(self):
return self.titulo

View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.