-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update readme
- Loading branch information
Showing
17 changed files
with
296 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
OUR_APPS = [ | ||
'web_pages', | ||
'web_app', | ||
'web_db' | ||
] | ||
|
||
INSTALLED_APPS = DJANGO_APPS + OUR_APPS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.contrib import admin | ||
|
||
from web_db import models | ||
|
||
|
||
class SongAdmin(admin.ModelAdmin): | ||
search_fields = ('title',) | ||
|
||
|
||
class SongInline(admin.TabularInline): | ||
model = models.Song | ||
|
||
|
||
class AlbumAdmin(admin.ModelAdmin): | ||
search_fields = ('title', 'artist', 'year',) | ||
inlines = (SongInline,) | ||
|
||
admin.site.register(models.Album, AlbumAdmin) | ||
admin.site.register(models.Song, SongAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class WebDbConfig(AppConfig): | ||
name = 'web_db' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.4 on 2017-09-03 00:16 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Album', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=255)), | ||
('year', models.PositiveIntegerField()), | ||
('artist', models.CharField(max_length=255)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Song', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=255)), | ||
('track', models.PositiveIntegerField(blank=True)), | ||
('duration', models.CharField(blank=True, max_length=15)), | ||
('album', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='web_db.Album')), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.4 on 2017-09-03 00:52 | ||
from __future__ import unicode_literals | ||
from collections import namedtuple | ||
|
||
from django.db import migrations | ||
|
||
|
||
MUSIC = [ | ||
{ | ||
'artist': 'Les Gordon', | ||
'title': 'Abyss', | ||
'year': '2016', | ||
'songs': [ | ||
{ | ||
'track': 1, | ||
'title': 'Abyss', | ||
'duration': '3:13' | ||
}, | ||
{ | ||
'track': 2, | ||
'title': 'Shiho & Kyoko', | ||
'duration': '2:58' | ||
}, | ||
] | ||
}, | ||
{ | ||
'artist': 'Same Gellaitry', | ||
'title': 'Escapism II', | ||
'year': '2016', | ||
'songs': [ | ||
{ | ||
'track': 1, | ||
'title': 'The Gateway', | ||
'duration': '3:12' | ||
}, | ||
{ | ||
'track': 2, | ||
'title': 'Desert Mirage', | ||
'duration': '5:00' | ||
}, | ||
{ | ||
'track': 3, | ||
'title': 'Jacket Weather', | ||
'duration': None | ||
}, | ||
{ | ||
'track': 4, | ||
'title': 'Static Sleep', | ||
'duration': '' | ||
} | ||
] | ||
} | ||
] | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('web_db', '0001_initial'), | ||
] | ||
|
||
def migrate_music(apps, schema_editor): | ||
Album = apps.get_model("web_db", "Album") | ||
Song = apps.get_model("web_db", "Song") | ||
for m in MUSIC: | ||
album = namedtuple('album', m.keys())(*m.values()) | ||
new_album = Album.objects.create( | ||
title=album.title, | ||
year=album.year, | ||
artist=album.artist | ||
) | ||
for s in album.songs: | ||
song = namedtuple('song', s.keys())(*s.values()) | ||
Song.objects.create( | ||
title=song.title, | ||
duration=song.duration or '', | ||
track=song.track, | ||
album=new_album | ||
) | ||
|
||
operations = [ | ||
migrations.RunPython(migrate_music, migrations.RunPython.noop), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.db import models | ||
|
||
|
||
class Album(models.Model): | ||
title = models.CharField(max_length=255) | ||
year = models.PositiveIntegerField() | ||
artist = models.CharField(max_length=255) | ||
|
||
def __str__(self): | ||
return "{} by {} ({})".format(self.title, self.artist, self.year) | ||
|
||
|
||
class Song(models.Model): | ||
title = models.CharField(max_length=255) | ||
track = models.PositiveIntegerField(blank=True) | ||
duration = models.CharField(max_length=15, blank=True) | ||
|
||
album = models.ForeignKey(Album) | ||
|
||
def __str__(self): | ||
return "{} ({})".format(self.title, self.track) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Album {{ album.title }}</title> | ||
</head> | ||
<body> | ||
<h3>{{ album.title }} by {{ album.artist }} ({{ album.year }})</h3> | ||
<h4>Songs:</h4> | ||
<ul> | ||
{% for song in album.song_set.all %} | ||
<li> | ||
<a href="{% url 'db:song-detail' song.pk %}">{{ song.track }} — {{ song.title }} {% if song.duration %}({{ song.duration }}){% endif %}</a> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
<a href="{% url 'db:album-list' %}">← back to album list</a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Albums</title> | ||
</head> | ||
<body> | ||
<h2>All Albums</h2> | ||
{% for album in albums %} | ||
<h3> | ||
<a href='{% url "db:album-detail" album.pk %}'> | ||
{{ album.title }} by {{ album.artist }} ({{ album.year }}) | ||
</a> | ||
</h3> | ||
<h4>Songs:</h4> | ||
<ul> | ||
{% for song in album.song_set.all %} | ||
<li> | ||
{{ song.track }} — {{ song.title }} {% if song.duration %}({{ song.duration }}){% endif %} | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
{% endfor %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Song {{ song.title }}</title> | ||
</head> | ||
<body> | ||
<h3>{{ song.track }}. {{ song.title }} {% if song.duration %}({{ song.duration }}){% endif %}</h3> | ||
<h4>album: <a href="{% url 'db:album-detail' song.album.pk %}">{{ song.album.title }}</a></h4> | ||
<a href="{% url 'db:song-list' %}">← back to song list</a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Song {{ song.title }}</title> | ||
</head> | ||
<body> | ||
<h3>All Songs</h3> | ||
<ul> | ||
{% for song in songs %} | ||
<li> | ||
<h3><a href="{% url 'db:song-detail' song.pk %}">{{ song.track }}. {{ song.title }} {% if song.duration %}({{ song.duration }}){% endif %}</a></h3> | ||
<h4>album: <a href="{% url 'db:album-detail' song.album.pk %}">{{ song.album.title }}</a></h4> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.conf.urls import url | ||
|
||
from web_db import views | ||
|
||
urlpatterns = [ | ||
url(r'^albums/$', views.AlbumListView.as_view(), name='album-list'), | ||
url(r'^albums/(?P<pk>\d+)/$', views.AlbumDetailView.as_view(), name='album-detail'), | ||
url(r'^songs/$', views.SongListView.as_view(), name='song-list'), | ||
url(r'^songs/(?P<pk>\d+)/$', views.SongDetailView.as_view(), name='song-detail'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.views.generic.detail import DetailView | ||
from django.views.generic.list import ListView | ||
|
||
from web_db.models import Album, Song | ||
|
||
|
||
class AlbumDetailView(DetailView): | ||
model = Album | ||
context_object_name = 'album' | ||
|
||
|
||
class AlbumListView(ListView): | ||
model = Album | ||
context_object_name = 'albums' | ||
|
||
|
||
class SongDetailView(DetailView): | ||
model = Song | ||
context_object_name = 'song' | ||
|
||
|
||
class SongListView(ListView): | ||
model = Song | ||
context_object_name = 'songs' |