Split Track column into name and artists
This commit is contained in:
@@ -45,7 +45,6 @@ class Track(models.Model):
|
|||||||
verbose_name_plural = "Tracks"
|
verbose_name_plural = "Tracks"
|
||||||
|
|
||||||
id = models.CharField(primary_key=True, max_length=MAX_ID)
|
id = models.CharField(primary_key=True, max_length=MAX_ID)
|
||||||
# artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
|
|
||||||
artists = models.ManyToManyField(Artist, blank=True)
|
artists = models.ManyToManyField(Artist, blank=True)
|
||||||
year = models.PositiveSmallIntegerField(null=True)
|
year = models.PositiveSmallIntegerField(null=True)
|
||||||
popularity = models.PositiveSmallIntegerField()
|
popularity = models.PositiveSmallIntegerField()
|
||||||
@@ -96,7 +95,7 @@ class History(models.Model):
|
|||||||
verbose_name_plural = "History"
|
verbose_name_plural = "History"
|
||||||
unique_together = (("user", "timestamp"),)
|
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)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
timestamp = models.DateTimeField()
|
timestamp = models.DateTimeField()
|
||||||
track = models.ForeignKey(Track, on_delete=models.CASCADE)
|
track = models.ForeignKey(Track, on_delete=models.CASCADE)
|
||||||
@@ -104,5 +103,12 @@ class History(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return " - ".join((str(self.user), str(self.timestamp), str(self.track)))
|
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)
|
||||||
|
|
||||||
# }}} #
|
# }}} #
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,23 @@ import django_tables2 as tables
|
|||||||
|
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from login.models import User
|
from login.models import User
|
||||||
from api.models import History
|
from api.models import History, Track
|
||||||
|
|
||||||
class HistoryTable(tables.Table):
|
class HistoryTable(tables.Table):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = History
|
model = History
|
||||||
template_name = 'django_tables2/bootstrap.html'
|
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):
|
def get_secret_context(user_secret):
|
||||||
"""Return user_secret in context for graph pages.
|
"""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)
|
user_id = get_user_id_from_secret(user_secret)
|
||||||
history_fields = [field.name for field in History._meta.get_fields()]
|
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 = History.objects.filter(user__exact=user_id).order_by('-timestamp')
|
||||||
user_history_table = HistoryTable(user_history)
|
user_history_table = HistoryTable(user_history)
|
||||||
return { 'user_id': user_id,
|
return { 'user_id': user_id,
|
||||||
'history_fields': history_fields,
|
'history_fields': history_fields,
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ body {
|
|||||||
background-color: #1e1e1e;
|
background-color: #1e1e1e;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1,th {
|
||||||
/* light grey */
|
/* light grey */
|
||||||
color: #e5e5e5;
|
color: #cccccc;
|
||||||
}
|
}
|
||||||
|
|
||||||
p,td {
|
p,td {
|
||||||
|
|||||||
Reference in New Issue
Block a user