Commit 646fe444 by Егор Юганов

lesson 18

1 parent 505f2e9b
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.10 (/usr/bin/python)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/website.iml" filepath="$PROJECT_DIR$/.idea/website.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
No preview for this file type
No preview for this file type
......@@ -2,6 +2,7 @@
from __future__ import unicode_literals
from django.contrib import admin
from .models import Album
from .models import Album, Song
admin.site.register(Album)
\ No newline at end of file
admin.site.register(Album)
admin.site.register(Song)
\ No newline at end of file
No preview for this file type
......@@ -9,10 +9,13 @@ class Album(models.Model):
genre = models.CharField(max_length=100)
album_logo = models.CharField(max_length=1000)
def __str__(self):
def __str__(self): # srting representation of an album
return self.album_title + ' - ' + self.artist
class Song(models.Model):
album = models.ForeignKey(Album, on_delete=models.CASCADE)
file_type = models.CharField(max_length=10)
song_title = models.CharField(max_length=250)
\ No newline at end of file
song_title = models.CharField(max_length=250)
def __str__(self):
return self.song_title
\ No newline at end of file
No preview for this file type
No preview for this file type
{{ album }}
\ No newline at end of file
{% if all_albums %}
<h3>Here are all my Albums</h3>
<ul>
{% for album in all_albums %}
<li><a href="/music/{{ album.id }}">{{ album.album_title }}</a></li>
......
from django.http import HttpResponse
from django.template import loader
from models import Album
from django.http import Http404
from django.shortcuts import render
from .models import Album
def index(request):
all_albums = Album.objects.all()
template = loader.get_template('music/index.html')
context = {
'all_albums': all_albums,
}
return HttpResponse(template.render(context, request))
context = {'all_albums': all_albums}
return render(request, 'music/index.html', context)
def detail(request, album_id):
return HttpResponse("<h2>Details for album id: " + str(album_id) + "</h2>")
\ No newline at end of file
try:
album = Album.objects.get(pk=album_id)
except Album.DoesNotExist:
raise Http404("Album does not exist")
return render(request, 'music/detail.html', {'album': album})
\ No newline at end of file
No preview for this file type
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!