Skip to content

Commit 20909af

Browse files
committed
views django
1 parent f6665b6 commit 20909af

17 files changed

+127
-8
lines changed
168 Bytes
Binary file not shown.
155 Bytes
Binary file not shown.
128 Bytes
Binary file not shown.
509 Bytes
Binary file not shown.

Django/catalog/admin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
from django.contrib import admin
2+
from .models import Author, Film, Genre, FilmInstance
23

34
# Register your models here.
5+
6+
admin.site.register(Author)
7+
admin.site.register(Film)
8+
admin.site.register(Genre)
9+
admin.site.register(FilmInstance)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 4.1 on 2022-08-07 17:39
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('catalog', '0002_author_film_alter_genre_name_filminstance_film_genre'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='film',
15+
name='isbn',
16+
),
17+
migrations.AddField(
18+
model_name='film',
19+
name='year',
20+
field=models.CharField(default='Null', help_text='Year of the film', max_length=4, verbose_name='year'),
21+
),
22+
migrations.AlterField(
23+
model_name='film',
24+
name='summary',
25+
field=models.TextField(help_text='Argumento breve de la película', max_length=1000, verbose_name='Summary'),
26+
),
27+
]

Django/catalog/models.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import uuid
44
# Create your models here.
55

6-
76
class Genre(models.Model):
87
name = models.CharField('Genre', max_length=64,help_text='Género de la película')
98

@@ -13,8 +12,8 @@ def __str__(self):
1312
class Film(models.Model):
1413
title = models.CharField('Title', max_length=64, help_text='Nombre de la película')
1514
author = models.ForeignKey('Author', on_delete=models.SET_NULL, null=True)
16-
summary = models.TextField('Summary', max_length=100, help_text='Argumento breve de la película')
17-
isbn = models.CharField('ISBN', max_length=13, help_text='ISBN de 13 caracteres')
15+
summary = models.TextField('Summary', max_length=1000, help_text='Argumento breve de la película')
16+
year = models.CharField('year', max_length=4, default='Null', help_text='Year of the film')
1817
genre = models.ManyToManyField(Genre)
1918

2019
def __str__(self):
@@ -38,6 +37,9 @@ class FilmInstance(models.Model):
3837
)
3938

4039
status = models.CharField(max_length=1, choices=LOAN_STATUS, blank=True, default='m', help_text='Disponibilidad de la película')
40+
41+
def __str__(self):
42+
return self.status
4143

4244
class Meta:
4345
ordering = ['due_back']
@@ -52,7 +54,7 @@ class Author(models.Model):
5254
date_of_death = models.DateField('Died', null=True, blank=True)
5355

5456
def __str__(self):
55-
return self.last_name
57+
return '%s (%s)' % (self.last_name, self.first_name)
5658

5759
def get_absolute_url(self):
5860
return reverse('book-detail', args=[str(self.id)])

Django/catalog/static/css/styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.sidebar_nav {
2+
margin-top: 20px;
3+
padding: 0;
4+
list-style: none;
5+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
{% block title %}Local Videoclub{% endblock %}
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
8+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
9+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
10+
11+
<!-- Add additional CSS in static file-->
12+
{% load static %}
13+
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
14+
15+
</head>
16+
<body>
17+
<div class="container-fluid">
18+
<div class="row">
19+
<div class ="col-sm-2">
20+
{% block sidebar %}
21+
<ul class="sidebar-nav">
22+
<li><a href="{% url 'index' %}">Home</a></li>
23+
<li><a href="">All films</a></li>
24+
<li><a href="">All authors</a></li>
25+
<li><a href="">All Genres</a></li>
26+
</ul>
27+
{% endblock %}
28+
</div>
29+
<div class="col-sm-10 ">
30+
{% block content %}{% endblock %}
31+
</div>
32+
</div>
33+
</div>
34+
</body>
35+
</html>

Django/catalog/templates/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{% extends "base_generic.html" %}
2+
3+
{% block content %}
4+
<h1>Local Videoclub Home</h1>
5+
<p>Welcome to <em>LocalVideoclub</em>, a very basic Django website developed as a tutorial example</p>
6+
7+
<h2>Dynamic content</h2>
8+
9+
<p>The Videoclub has the following records counts:</p>
10+
<ul>
11+
<li><strong>Films:</strong>{{ num_films }} </li>
12+
<li><strong>Authors:</strong>{{ num_authors }} </li>
13+
<li><strong>Genres:</strong>{{ num_genres }} </li>
14+
<li><strong>Copies:</strong>{{ num_instances }} </li>
15+
<li><strong>Copies available:</strong>{{ available }} </li>
16+
17+
</ul>
18+
{% endblock %}

Django/catalog/urls.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#from django.conf.urls import url
2-
#from . import views
1+
from django.urls import re_path as url
2+
from . import views
33

4-
urlpatterns = []
4+
urlpatterns = [
5+
url(r'^$', views.index, name='index') # cuando la petición sea NADA dispara la función index del módulo views
6+
]

Django/catalog/views.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
from django.shortcuts import render
2+
from .models import Author, Film, Genre, FilmInstance
23

34
# Create your views here.
5+
6+
def index(request):
7+
num_films = Film.objects.all().count()
8+
num_instances = FilmInstance.objects.all().count()
9+
num_authors = Author.objects.all().count()
10+
num_genres = Genre.objects.all().count()
11+
12+
available = FilmInstance.objects.filter(status__exact='a'). count()
13+
14+
return render( # contexto
15+
request,
16+
'index.html',
17+
context={
18+
'num_films': num_films,
19+
'num_authors': num_authors,
20+
'num_genres': num_genres,
21+
'num_instances': num_instances,
22+
'available': available,
23+
}
24+
)

Django/db.sqlite3

4 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

Django/movieAuthors/urls.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
"""
1616
from django.contrib import admin
1717
from django.urls import path, include
18+
from django.conf import settings
19+
from django.conf.urls.static import static
1820

1921
urlpatterns = [
2022
path('admin/', admin.site.urls),
2123
path('catalog/', include('catalog.urls'))
22-
]
24+
25+
] + static(settings.STATIC_URL, document_root = settings.STATIC_ROOT)

0 commit comments

Comments
 (0)