Honestly this was really fun to do. I am pretty proud to build an app to successfully work. I was able to create multiple differnt routes including adding movies, searching, updating status, rating, and genre. This project has made me realize how useful it is to understanding how apps are developed. I feel like this is super applicable and super knowledgable to understand. Some skills I learned with this project is how to design and build models, create API routes, working databases, and handling errors.

This commit is contained in:
erbrown2
2026-05-17 18:24:25 -04:00
parent 7f36330fc9
commit 91496c9254
7 changed files with 159 additions and 0 deletions

BIN
project/app/database.sqlite Normal file

Binary file not shown.

View File

@@ -0,0 +1,29 @@
# Generated by Django 5.2.11 on 2026-05-17 21:25
import banjo.models
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Movie',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', banjo.models.StringField(default='')),
('year', banjo.models.IntegerField(blank=True, default=0, null=True)),
('genre', banjo.models.StringField(blank=True, default='')),
('status', banjo.models.StringField(default='')),
('rating', banjo.models.IntegerField(blank=True, default=0, null=True)),
],
options={
'abstract': False,
},
),
]

View File

@@ -0,0 +1,19 @@
# Generated by Django 5.2.11 on 2026-05-17 21:35
import banjo.models
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('app', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='movie',
name='genre',
field=banjo.models.StringField(blank=True, default='', null=True),
),
]

View File

@@ -0,0 +1,17 @@
# Generated by Django 5.2.11 on 2026-05-17 22:11
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('app', '0002_alter_movie_genre'),
]
operations = [
migrations.RemoveField(
model_name='movie',
name='year',
),
]

View File

24
project/app/models.py Normal file
View File

@@ -0,0 +1,24 @@
from banjo.models import (
Model,
StringField,
IntegerField,
FloatField,
ForeignKey,
)
from django.db.models import DateTimeField
class Movie(Model):
title = StringField()
genre = StringField(blank = True, null = True)
status = StringField(default = "Want to Watch")
rating = IntegerField(blank = True, null = True)
def to_dict(self):
return {
"id": self.id,
"title": self.title,
"genre": self.genre,
"status": self.status,
"rating": self.rating,
}

70
project/app/views.py Normal file
View File

@@ -0,0 +1,70 @@
from banjo.urls import route_get, route_post
from banjo.http import BadRequest
from app.models import Movie
@route_get('movies/all')
def all_movies(params):
movies = Movie.objects.all()
return {'movies': [movie.to_dict() for movie in movies]}
@route_get('movies/search', args={'query': str})
def search_movie(params):
query = params['query']
movies = Movie.objects.filter(title__icontains=query)
return {'movies': [movie.to_dict() for movie in movies]}
@route_get('movies/want-to-watch')
def want_to_watch(params):
movies = Movie.objects.filter(status="Want to Watch")
return {'movies': [movie.to_dict() for movie in movies]}
@route_get('movies/watched')
def watched_movies(params):
movies = Movie.objects.filter(status="Watched")
return {'movies': [movie.to_dict() for movie in movies]}
@route_post('movies/add', args={'title': str})
def add_movie(params):
movie = Movie(
title=params['title'],
genre=params.get('genre'),
status=params.get('status', 'Want to Watch'),
rating=params.get('rating')
)
movie.save()
return movie.to_dict()
@route_post('movies/update-status', args={'id': int, 'status': str})
def update_status(params):
try:
movie = Movie.objects.get(id=params['id'])
movie.status = params['status']
movie.save()
return movie.to_dict()
except Movie.DoesNotExist:
raise NotFound("Movie not found")
@route_post('movies/update-rating', args={'id': int, 'rating': int})
def update_rating(params):
try:
movie = Movie.objects.get(id=params['id'])
rating = params['rating']
if rating < 1 or rating > 10:
raise BadRequest("Rating must be between 1 and 10")
movie.rating = rating
movie.save()
return movie.to_dict()
except Movie.DoesNotExist:
raise NotFound("Movie not found")
@route_post('movies/update-genre', args={'id': int, 'genre': str})
def update_genre(params):
"""Update the genre of an existing movie"""
try:
movie = Movie.objects.get(id=params['id'])
movie.genre = params['genre']
movie.save()
return movie.to_dict()
except Movie.DoesNotExist:
raise NotFound("Movie not found")