Permalink
Browse files

it worksgit add -A! django successgit add -A

  • Loading branch information...
DJatlien committed Dec 6, 2018
1 parent aaba8d6 commit 940309ff903dce852a2926bbdf6e5cf766771f0b
View
No changes.
View
@@ -0,0 +1,5 @@
from django.contrib import admin
from main.models import Artist, Song
admin.site.register([Artist, Song])
View
@@ -0,0 +1,5 @@
from django.apps import AppConfig
class MainConfig(AppConfig):
name = 'main'
@@ -0,0 +1,34 @@
# Generated by Django 2.1.4 on 2018-12-06 19:19
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Artist',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('photo_url', models.CharField(blank=True, max_length=400, null=True)),
('nationality', 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)),
('album', models.CharField(max_length=255)),
('preview_url', models.CharField(max_length=400)),
('artist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='songs', to='main.Artist')),
],
),
]
No changes.
View
@@ -0,0 +1,19 @@
# In main/models.py
from django.db import models
class Artist(models.Model):
name = models.CharField(max_length=200)
photo_url = models.CharField(max_length=400, null=True, blank=True)
nationality = models.CharField(max_length=255)
def __str__(self):
return self.name
class Song(models.Model):
title = models.CharField(max_length=255)
album = models.CharField(max_length=255)
preview_url = models.CharField(max_length=400)
artist = models.ForeignKey(Artist, on_delete=models.CASCADE, related_name='songs')
def __str__(self):
return self.title
View
@@ -0,0 +1,16 @@
from rest_framework import serializers
from .models import Artist, Song
class SongSerializer(serializers.ModelSerializer):
class Meta:
model = Song
fields = ('id', 'title', 'album', 'preview_url', 'artist')
class ArtistSerializer(serializers.ModelSerializer):
songs = SongSerializer(many=True, read_only=True)
class Meta:
model = Artist
fields = ('id', 'name', 'photo_url', 'nationality', 'songs')
View
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
View
@@ -0,0 +1,13 @@
from django.urls import path, include
from rest_framework import routers
from . import views
router = routers.DefaultRouter()
router.register('artists', views.ArtistView)
router.register('songs', views.SongView)
urlpatterns = [
path('', include(router.urls))
]
View
@@ -0,0 +1,17 @@
from rest_framework import viewsets
from .serializers import ArtistSerializer, SongSerializer
from .models import Artist, Song
class ArtistView(viewsets.ModelViewSet):
queryset = Artist.objects.all()
serializer_class = ArtistSerializer
class SongView(viewsets.ModelViewSet):
queryset = Song.objects.all()
serializer_class = SongSerializer
View
@@ -43,7 +43,9 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'django_extensions'
'django_extensions',
'main',
'tunr_react'
]
MIDDLEWARE = [
View
@@ -15,14 +15,15 @@
"""
from django.conf.urls import url
from django.contrib import admin
from django.urls import path
from django.urls import path, include
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('api/', include('main.urls')),
path('admin/', admin.site.urls),
url(r'^$', views.FrontendAppView.as_view())
]

0 comments on commit 940309f

Please sign in to comment.