Browse Source

Split Track column into name and artists

master
Kevin Mok 6 years ago
parent
commit
4b19c932b0
  1. 10
      api/models.py
  2. 14
      graphs/utils.py
  3. 4
      static/css/dark_bg.css

10
api/models.py

@ -45,7 +45,6 @@ class Track(models.Model):
verbose_name_plural = "Tracks"
id = models.CharField(primary_key=True, max_length=MAX_ID)
# artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
artists = models.ManyToManyField(Artist, blank=True)
year = models.PositiveSmallIntegerField(null=True)
popularity = models.PositiveSmallIntegerField()
@ -96,7 +95,7 @@ class History(models.Model):
verbose_name_plural = "History"
unique_together = (("user", "timestamp"),)
history_id = models.AutoField(primary_key=True)
id = models.AutoField(primary_key=True)
user = models.ForeignKey(User, on_delete=models.CASCADE)
timestamp = models.DateTimeField()
track = models.ForeignKey(Track, on_delete=models.CASCADE)
@ -104,5 +103,12 @@ class History(models.Model):
def __str__(self):
return " - ".join((str(self.user), str(self.timestamp), str(self.track)))
def get_track_name(self):
return self.track.name
def get_artists(self):
artist_names = [artist.name for artist in self.track.artists.all()]
return ', '.join(artist_names)
# }}} #

14
graphs/utils.py

@ -2,13 +2,23 @@ import django_tables2 as tables
from pprint import pprint
from login.models import User
from api.models import History
from api.models import History, Track
class HistoryTable(tables.Table):
class Meta:
model = History
template_name = 'django_tables2/bootstrap.html'
track_name = tables.Column(accessor='get_track_name', orderable=False)
artists = tables.Column(accessor='get_artists', orderable=False)
# def render_track_name(self, record):
# return record.track.name
# return record.user
# def render_user(self, value):
# return ''
def get_secret_context(user_secret):
"""Return user_secret in context for graph pages.
@ -28,7 +38,9 @@ def get_user_history(user_secret):
"""
user_id = get_user_id_from_secret(user_secret)
history_fields = [field.name for field in History._meta.get_fields()]
# don't need ordering bc. django-tables2?
user_history = History.objects.filter(user__exact=user_id).order_by('-timestamp')
# user_history = History.objects.filter(user__exact=user_id).order_by('-timestamp')
user_history_table = HistoryTable(user_history)
return { 'user_id': user_id,
'history_fields': history_fields,

4
static/css/dark_bg.css

@ -3,9 +3,9 @@ body {
background-color: #1e1e1e;
}
h1 {
h1,th {
/* light grey */
color: #e5e5e5;
color: #cccccc;
}
p,td {

Loading…
Cancel
Save