Browse Source

Change artists field in Track

artists is now a ManyToManyField in Track, which is cleaner than
using a unique_together clause in the Meta class.
master
Chris Shyi 7 years ago
parent
commit
27718743d7
  1. 10
      spotifyvis/migrations/0001_initial.py
  2. 8
      spotifyvis/migrations/0002_auto_20180605_2347.py
  3. 18
      spotifyvis/migrations/0003_auto_20180605_0211.py
  4. 5
      spotifyvis/models.py
  5. 2
      spotifyvis/views.py

10
spotifyvis/migrations/0001_initial.py

@ -1,4 +1,4 @@
# Generated by Django 2.0.5 on 2018-06-03 23:01
# Generated by Django 2.0.5 on 2018-06-05 20:53
from django.db import migrations, models
import django.db.models.deletion
@ -43,7 +43,7 @@ class Migration(migrations.Migration):
name='User',
fields=[
('user_id', models.CharField(max_length=30, primary_key=True, serialize=False)),
('username', models.CharField(max_length=30)),
('user_name', models.CharField(blank=True, max_length=30)),
],
options={
'verbose_name': 'User',
@ -71,15 +71,11 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='track',
name='artist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='spotifyvis.Artist'),
field=models.ManyToManyField(to='spotifyvis.Artist'),
),
migrations.AddField(
model_name='track',
name='users',
field=models.ManyToManyField(to='spotifyvis.User'),
),
migrations.AlterUniqueTogether(
name='track',
unique_together={('track_id', 'artist')},
),
]

8
spotifyvis/migrations/0002_auto_20180605_0209.py → spotifyvis/migrations/0002_auto_20180605_2347.py

@ -1,4 +1,4 @@
# Generated by Django 2.0.5 on 2018-06-05 02:09
# Generated by Django 2.0.5 on 2018-06-05 23:47
from django.db import migrations
@ -11,8 +11,8 @@ class Migration(migrations.Migration):
operations = [
migrations.RenameField(
model_name='user',
old_name='username',
new_name='user_name',
model_name='track',
old_name='artist',
new_name='artists',
),
]

18
spotifyvis/migrations/0003_auto_20180605_0211.py

@ -1,18 +0,0 @@
# Generated by Django 2.0.5 on 2018-06-05 02:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('spotifyvis', '0002_auto_20180605_0209'),
]
operations = [
migrations.AlterField(
model_name='user',
name='user_name',
field=models.CharField(blank=True, max_length=30),
),
]

5
spotifyvis/models.py

@ -24,7 +24,7 @@ class User(models.Model):
user_name = models.CharField(max_length=30, blank=True) # User's Spotify user name, if set
def __str__(self):
return self.username
return self.user_name
class Track(models.Model):
@ -32,10 +32,9 @@ class Track(models.Model):
class Meta:
verbose_name = "Track"
verbose_name_plural = "Tracks"
unique_together = ('track_id', 'artist',)
track_id = models.CharField(max_length=30)
artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
artists = models.ManyToManyField(Artist)
year = models.PositiveSmallIntegerField()
popularity = models.DecimalField(decimal_places=2, max_digits=2)
runtime = models.PositiveSmallIntegerField()

2
spotifyvis/views.py

@ -16,6 +16,7 @@ TRACKS_TO_QUERY = 5
# generate_random_string {{{ #
def generate_random_string(length):
"""Generates a random string of a certain length
@ -145,6 +146,7 @@ def user_data(request):
user = User.objects.get(user_id=request.session['user_id'])
except User.DoesNotExist:
user = User.objects.create(user_id=request.session['user_id'], user_name=request.session['user_name'])
user.save()
context = {
'user_name': user_data_response['display_name'],

Loading…
Cancel
Save