Commit bd994527 authored by Gink's avatar Gink

Finalize models and enable database connection with Django

> To initialize, delete db.sqlite3, then run
> python manage.py makemigrations mymusiclist
> python manage.py migrate
> Then you populate db.sqlite3 by sourcing SQL/sqlite3.sql
parent 240264c1
...@@ -3,7 +3,7 @@ mymusiclist.sql ...@@ -3,7 +3,7 @@ mymusiclist.sql
convert convert
extract.sql extract.sql
Assuming you have sqlite3 installed, Assuming you have sqlite3 installed and Django setup with migrations,
While in same directory as db.sqlite3, run: While in same directory as db.sqlite3, run:
Sqlite3 Sqlite3
......
...@@ -62,8 +62,8 @@ create table tag_entry( ...@@ -62,8 +62,8 @@ create table tag_entry(
FOREIGN KEY (entry_id) REFERENCES music_entry(id) FOREIGN KEY (entry_id) REFERENCES music_entry(id)
); );
-- assuming we have featured songs -- assuming we have featured songs
-- currently unused
create table featured_songs( create table featured_songs(
song_id int unique, song_id int unique,
......
This diff is collapsed.
This diff is collapsed.
from django.db import models from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
class user_account(models.Model): class user_account(models.Model):
  • Unless there's additional fields aside from username, email, first and last name, no need for this class, the User class is enough

  • i removed both dba

Please register or sign in to reply
id = models.AutoField(primary_key=true) id = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=64) first_name = models.CharField(max_length=64)
last_name = models.CharField(max_length=64) last_name = models.CharField(max_length=64)
email = models.CharField(max_length=64) email = models.CharField(max_length=64)
class artist(models.Model): class artist(models.Model):
id = models.AutoField(primary_key=true) id = models.AutoField(primary_key=True)
name = models.CharField(max_length=64) name = models.CharField(max_length=64)
description = models.TextField() description = models.TextField()
class album(models.Model): class album(models.Model):
id = models.AutoField(primary_key=true) id = models.AutoField(primary_key=True)
album_name = models.CharField(max_length=64) album_name = models.CharField(max_length=64)
year = models.DecimalField(max_digits=4, decimal_places=0) year = models.DecimalField(max_digits=4, decimal_places=0)
# FOREIGN KEY artist_id artist = models.ForeignKey(artist)
class song(models.Model): class song(models.Model):
id = models.AutoField(primary_key=true) id = models.AutoField(primary_key=True)
song_name = models.TextField() song_name = models.TextField()
genre = models.CharField(max_length=128) genre = models.CharField(max_length=128)
song_length = models.PositiveIntegerField(default=0) song_length = models.PositiveIntegerField(default=0, null=True)
lyrics = models.TextField() lyrics = models.TextField(null=True)
#FOREIGN KEY ARTISTID artist = models.ForeignKey(artist)
#FOREIGN KEY ALBUMID album = models.ForeignKey(album)
class music_playlist(models.Model): class music_playlist(models.Model):
id = models.AutoField(primary_key=true) id = models.AutoField(primary_key=True)
playlist_name = models.CharField(max_length=32) playlist_name = models.CharField(max_length=32)
is_public = models.BooleanField(default=false) is_public = models.BooleanField(default=False)
#FOREIGN KEY TO user_account user = models.ForeignKey(user_account)
class music_entry(models.Model): class music_entry(models.Model):
RATING_CHOICES = ( RATING_CHOICES = (
...@@ -47,12 +45,13 @@ class music_entry(models.Model): ...@@ -47,12 +45,13 @@ class music_entry(models.Model):
(8,'9'), (8,'9'),
(9,'10') (9,'10')
) )
id = models.AutoField(primary_key=true) id = models.AutoField(primary_key=True)
order_in_playlist = models.PositiveSmallIntegerField() order_in_playlist = models.PositiveSmallIntegerField()
rating = models.DecimalField(max_digits=1, decimal_places=0, choices=RATING_CHOICES) rating = models.DecimalField(max_digits=1, decimal_places=0, choices=RATING_CHOICES)
#FOREIGN KEY TO PLAYLIST playlist = models.ForeignKey(music_playlist)
#FOREIGN KEY TO SONG song = models.ForeignKey(song)
class tag(models.Model): class tag(models.Model):
id = models.AutoField(primary_key=true) id = models.AutoField(primary_key=True)
name = models.CharField(max_length=32) name = models.CharField(max_length=32)
tag = models.ManyToManyField(music_entry)
...@@ -32,12 +32,13 @@ ALLOWED_HOSTS = [] ...@@ -32,12 +32,13 @@ ALLOWED_HOSTS = []
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'core',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles'
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment