Compare commits

...

1 Commits

Author SHA1 Message Date
fc715c3ced initial movies app 2026-02-28 13:04:19 -05:00
15 changed files with 197 additions and 1 deletions

0
apps/movies/__init__.py Normal file
View File

9
apps/movies/admin.py Normal file
View File

@@ -0,0 +1,9 @@
from django.contrib import admin
from .models import MediaFormat, Movie
# Register your models here.
# Register your models here.
admin.site.register(Movie)
admin.site.register(MediaFormat)

5
apps/movies/apps.py Normal file
View File

@@ -0,0 +1,5 @@
from django.apps import AppConfig
class MoviesConfig(AppConfig):
name = "apps.movies"

View File

@@ -0,0 +1,32 @@
# Generated by Django 6.0 on 2026-02-28 17:08
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='MediaFormat',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
],
),
migrations.CreateModel(
name='Movie',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=200)),
('release_date', models.DateField()),
('pub_date', models.DateTimeField(verbose_name='date published')),
('media_formats', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='movies.mediaformat')),
],
),
]

View File

@@ -0,0 +1,26 @@
# Generated by Django 6.0 on 2026-02-28 17:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('movies', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='movie',
name='pub_date',
),
migrations.RemoveField(
model_name='movie',
name='media_formats',
),
migrations.AddField(
model_name='movie',
name='media_formats',
field=models.ManyToManyField(to='movies.mediaformat'),
),
]

View File

@@ -0,0 +1,20 @@
# Generated by Django 6.0 on 2026-02-28 17:38
import django.utils.timezone
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('movies', '0002_remove_movie_pub_date_remove_movie_media_formats_and_more'),
]
operations = [
migrations.AddField(
model_name='movie',
name='added_date',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
]

View File

21
apps/movies/models.py Normal file
View File

@@ -0,0 +1,21 @@
from django.db import models
from django.utils import timezone
# Create your models here.
class MediaFormat(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return self.name
class Movie(models.Model):
title = models.CharField(max_length=200)
release_date = models.DateField()
media_formats = models.ManyToManyField(MediaFormat)
added_date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title

View File

@@ -0,0 +1,52 @@
<!doctype html>
<title>Movies Homepage</title>
<style>
.table-hover {
width: 100%;
border-collapse: collapse;
font-family: sans-serif;
font-size: 0.9rem;
text-align: left;
}
.table-hover thead th {
/* Style for the header */
padding: 12px 15px;
background-color: #f4f4f4;
border-bottom: 2px solid #ccc;
text-align: left;
}
.table-hover td {
padding: 12px 15px;
border-bottom: 1px solid #e0e0e0;
}
/* This is the key part of the template */
.table-hover tbody tr:hover {
background-color: #f5f5f5; /* A light grey for the highlight */
cursor: pointer; /* Changes the cursor to a pointer to indicate interactivity */
}
</style>
<table class="table-hover">
<thead>
<tr>
<th scope="col">Title</th>
<th scope="col">Release Date</th>
<th scope="col">Date Added</th>
<th scope="col">Formats</th>
</tr>
</thead>
<tbody>
{% for m in latest_movies %}
<tr>
<th>{{ m.title }}</th>
<th>{{ m.release_date }}</th>
<th>{{ m.added_date }}</th>
<th>{{ m.media_formats }}</th>
</tr>
{% endfor %}
</tbody>
</table>

3
apps/movies/tests.py Normal file
View File

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

7
apps/movies/urls.py Normal file
View File

@@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path("", views.IndexView.as_view(), name="index"),
]

18
apps/movies/views.py Normal file
View File

@@ -0,0 +1,18 @@
from django.http import HttpResponse
from django.shortcuts import render
from django.views import generic
from .models import Movie
def index(request):
return HttpResponse("Hello, world. You're at the movies index.")
class IndexView(generic.ListView):
template_name = "movies/index.html"
context_object_name = "latest_movies"
def get_queryset(self):
"""Return the last five published questions."""
return Movie.objects.order_by("-added_date")[:5]

View File

@@ -1,6 +1,7 @@
from django.contrib import admin
from .models import Question
from .models import Choice, Question
# Register your models here.
admin.site.register(Question)
admin.site.register(Choice)

View File

@@ -32,6 +32,7 @@ ALLOWED_HOSTS = []
INSTALLED_APPS = [
"apps.polls.apps.PollsConfig",
"apps.movies.apps.MoviesConfig",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",

View File

@@ -21,4 +21,5 @@ from django.urls import include, path
urlpatterns = [
path("admin/", admin.site.urls),
path("polls/", include("apps.polls.urls")),
path("", include("apps.movies.urls")),
]