This commit is contained in:
Andros Fenollosa
2021-06-22 15:43:26 +02:00
parent 3ce1665ca0
commit a901b8d54a
26 changed files with 368 additions and 0 deletions

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

9
app/api/admin.py Normal file
View File

@ -0,0 +1,9 @@
from django.contrib import admin
from app.api.models import News
@admin.register(News)
class NewsAdmin(admin.ModelAdmin):
readonly_fields = ('votes',)
list_display = ('title', 'url')

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

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

View File

@ -0,0 +1,24 @@
# Generated by Django 3.2.4 on 2021-06-22 10:46
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='News',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('url', models.CharField(max_length=500)),
('votes', models.IntegerField()),
('created', models.DateTimeField(auto_now_add=True)),
],
),
]

View File

15
app/api/models.py Normal file
View File

@ -0,0 +1,15 @@
from django.db import models
class News(models.Model):
title = models.CharField(max_length=50)
url = models.CharField(max_length=500)
votes = models.IntegerField(default=0)
created = models.DateTimeField(auto_now_add=True)
class Meta:
verbose_name = "News"
verbose_name_plural = "News"
def __str__(self):
return self.title

9
app/api/serializers.py Normal file
View File

@ -0,0 +1,9 @@
from app.api.models import News
from rest_framework import serializers
class NewsSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = News
fields = ['title', 'url', 'created']

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

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

11
app/api/views.py Normal file
View File

@ -0,0 +1,11 @@
from app.api.models import News
from rest_framework import viewsets
from app.api.serializers import NewsSerializer
class NewsViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows News to be viewed or edited.
"""
queryset = News.objects.all()
serializer_class = NewsSerializer

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

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

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

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

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

View File

View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %} | Djanker News</title>
</head>
<body>
<header>
<ul>
<li>
<a href="{% url 'list' %}">List</a>
</li>
<li>
<a href="{% url 'add-news' %}">Add News</a>
</li>
</ul>
</header>
<main>
<h1>Djanker News</h1>
{% block main %}{% endblock %}
</main>
<footer>
2021 Djanker News
</footer>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,12 @@
{% extends 'layouts/base.html' %}
{% block title %}Welcome{% endblock %}
{% block main %}
{% for item in news %}
<article>
<h2>{{ item.title }}</h2>
<p>
<a href="{{ item.url }}">Ver completo</a>
</p>
</article>
{% endfor %}
{% endblock %}

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

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

12
app/web/views.py Normal file
View File

@ -0,0 +1,12 @@
from django.shortcuts import render
from app.api.models import News
def home(request):
return render(request, 'pages/list.html', {
'news': News.objects.all()
})
def add_news(request):
return render(request, 'pages/add-news.html', {})