First commit

This commit is contained in:
Andros Fenollosa
2021-11-08 23:32:13 +01:00
parent 088081247c
commit b57103eabd
19 changed files with 496 additions and 0 deletions

0
app/website/__init__.py Normal file
View File

3
app/website/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
app/website/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class WebsiteConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app.website'

View File

77
app/website/models.py Normal file
View File

@ -0,0 +1,77 @@
from django.db import models
class Profile(AbstractBaseUser):
"""User model"""
email = models.EmailField("Email", unique=True)
full_name = models.CharField(
max_length=100, verbose_name="Nombre y apellidos", default="Sapps"
)
avatar = models.ImageField(verbose_name="Avatar", upload_to="uploads/avatars/")
USERNAME_FIELD = "email" # make the user log in with the email
def __str__(self):
return self.email
class Category(models.Model):
"""Category model"""
name = models.CharField(max_length=100, verbose_name="Nombre")
class Meta:
ordering = ("name",)
verbose_name = "Categoria"
verbose_name_plural = "Categorias"
def __str__(self):
return self.name
class Talk(models.Model):
"""Talk model"""
title = models.CharField(max_length=100, verbose_name="Título")
category = models.ForeignKey(
Category,
on_delete=models.SET_NULL,
null=True,
related_name="Categoría",
verbose_name="Categoría",
)
author = models.ForeignKey(
Profile,
on_delete=models.SET_NULL,
null=True,
related_name="author",
verbose_name="Autor",
)
image = models.ImageField(verbose_name="Imagen", upload_to="uploads/articles/")
is_draft = models.BooleanField(default=True, verbose_name="¿Es un borrador?")
content = tinymce_models.HTMLField(verbose_name="Contenido")
created_at = models.DateTimeField(auto_now=True, verbose_name="Creado")
@property
def slug(self):
return slugify(self.title)
@property
def reading_time_min(self):
# https://help.medium.com/hc/en-us/articles/214991667-Read-time
READING_SPEED_OF_AN_ADULT = 265
return ceil(
len(strip_tags(self.content).split(" ")) / READING_SPEED_OF_AN_ADULT
)
class Meta:
ordering = ("-created_at",)
verbose_name = "Charla"
verbose_name_plural = "Charlas"
def __str__(self):
return self.title

3
app/website/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
app/website/views.py Normal file
View File

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