Browse Source

Modify maximum field length

Artist.genre and Track.name had maximum lengths that were not long enough, now increased.
master
Chris Shyi 7 years ago
parent
commit
92d5d174e8
  1. 18
      spotifyvis/migrations/0002_auto_20180608_2002.py
  2. 18
      spotifyvis/migrations/0003_auto_20180608_2007.py
  3. 4
      spotifyvis/models.py
  4. 3
      spotifyvis/utils.py

18
spotifyvis/migrations/0002_auto_20180608_2002.py

@ -0,0 +1,18 @@
# Generated by Django 2.0.5 on 2018-06-09 00:02
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('spotifyvis', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='artist',
name='genre',
field=models.CharField(max_length=30),
),
]

18
spotifyvis/migrations/0003_auto_20180608_2007.py

@ -0,0 +1,18 @@
# Generated by Django 2.0.5 on 2018-06-09 00:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('spotifyvis', '0002_auto_20180608_2002'),
]
operations = [
migrations.AlterField(
model_name='track',
name='name',
field=models.CharField(max_length=150),
),
]

4
spotifyvis/models.py

@ -13,7 +13,7 @@ class Artist(models.Model):
artist_id = models.CharField(primary_key=True, max_length=MAX_ID) artist_id = models.CharField(primary_key=True, max_length=MAX_ID)
# unique since only storing one genre per artist right now # unique since only storing one genre per artist right now
name = models.CharField(unique=True, max_length=50) name = models.CharField(unique=True, max_length=50)
genre = models.CharField(max_length=20)
genre = models.CharField(max_length=30)
def __str__(self): def __str__(self):
return self.name return self.name
@ -49,7 +49,7 @@ class Track(models.Model):
year = models.PositiveSmallIntegerField() year = models.PositiveSmallIntegerField()
popularity = models.PositiveSmallIntegerField() popularity = models.PositiveSmallIntegerField()
runtime = models.PositiveSmallIntegerField() runtime = models.PositiveSmallIntegerField()
name = models.CharField(max_length=75)
name = models.CharField(max_length=150)
users = models.ManyToManyField(User, blank=True) users = models.ManyToManyField(User, blank=True)
def __str__(self): def __str__(self):

3
spotifyvis/utils.py

@ -90,6 +90,7 @@ def save_track_obj(track_dict, artists, user):
:returns: (The created/retrieved Track object, created) :returns: (The created/retrieved Track object, created)
""" """
print(track_dict['name'])
new_track, created = Track.objects.get_or_create( new_track, created = Track.objects.get_or_create(
track_id=track_dict['id'], track_id=track_dict['id'],
year=track_dict['album']['release_date'].split('-')[0], year=track_dict['album']['release_date'].split('-')[0],
@ -308,7 +309,7 @@ def update_artist_genre(headers, artist_obj):
:returns: None :returns: None
""" """
artist_response = requests.get('https://api.spotify.com/v1/artists/' + artist_obj.id, headers=headers).json()
artist_response = requests.get('https://api.spotify.com/v1/artists/' + artist_obj.artist_id, headers=headers).json()
# update genre for artist in database with top genre # update genre for artist in database with top genre
artist_obj.genre = artist_response['genres'][0] artist_obj.genre = artist_response['genres'][0]
artist_obj.save() artist_obj.save()

Loading…
Cancel
Save