feat: Add homepage app

This commit is contained in:
Thomas Schwery 2022-03-06 10:49:36 +01:00
parent 4ba636a9d3
commit 28567f31ca
13 changed files with 117 additions and 0 deletions

View file

@ -33,6 +33,7 @@ ALLOWED_HOSTS = []
INSTALLED_APPS = [
'tea.apps.TeaConfig',
'wine.apps.WineConfig',
'homepage.apps.HomepageConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',

View file

@ -18,6 +18,7 @@ from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('homepage.urls')),
path('tea/', include('tea.urls')),
path('wine/', include('wine.urls')),
]

0
homepage/__init__.py Normal file
View file

6
homepage/admin.py Normal file
View file

@ -0,0 +1,6 @@
from django.contrib import admin
from .models import Application
admin.site.register(Application)

6
homepage/apps.py Normal file
View file

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

View file

@ -0,0 +1,22 @@
# Generated by Django 4.0.2 on 2022-03-06 09:12
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Application',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('url', models.CharField(max_length=20)),
],
),
]

View file

9
homepage/models.py Normal file
View file

@ -0,0 +1,9 @@
from django.db import models
class Application(models.Model):
name = models.CharField(max_length=200)
url = models.CharField(max_length=20)
def __str__(self):
return self.name

View file

@ -0,0 +1,40 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<title>Django StockPile</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="/">Django StockPile</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/tea">Thés</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/wine">Vins</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<div class="row justify-content-center">
<div class="col-8">
<hr class="mt-0 mb-4">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,7 @@
{% extends 'homepage/base.html' %}
{% block content %}
{% for application in application_list %}
<h2><a href='{{ application.url }}'>{{ application.name }}</a></h2>
{% endfor %}
{% endblock %}

3
homepage/tests.py Normal file
View file

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

8
homepage/urls.py Normal file
View file

@ -0,0 +1,8 @@
from django.urls import path
from . import views
app_name = 'homepage'
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
]

14
homepage/views.py Normal file
View file

@ -0,0 +1,14 @@
from django.db.models import F
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, get_object_or_404
from django.urls import reverse
from django.views import generic
from .models import Application
class IndexView(generic.ListView):
model = Application
template_name = 'homepage/index.html'
def get_queryset(self):
return Application.objects.order_by('name')