Skip to content
Snippets Groups Projects
Commit 0786c58d authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Fixed #33: sort by track position in album in API vy default, also reuse that...

Fixed #33: sort by track position in album in API vy default, also reuse that information on frontend side
parent f1c05d4f
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ class APIModelMixin(models.Model): ...@@ -27,6 +27,7 @@ class APIModelMixin(models.Model):
api_includes = [] api_includes = []
creation_date = models.DateTimeField(default=timezone.now) creation_date = models.DateTimeField(default=timezone.now)
import_hooks = [] import_hooks = []
class Meta: class Meta:
abstract = True abstract = True
ordering = ['-creation_date'] ordering = ['-creation_date']
...@@ -291,6 +292,9 @@ class Track(APIModelMixin): ...@@ -291,6 +292,9 @@ class Track(APIModelMixin):
] ]
tags = TaggableManager() tags = TaggableManager()
class Meta:
ordering = ['album', 'position']
def __str__(self): def __str__(self):
return self.title return self.title
...@@ -386,6 +390,8 @@ class ImportJob(models.Model): ...@@ -386,6 +390,8 @@ class ImportJob(models.Model):
) )
status = models.CharField(choices=STATUS_CHOICES, default='pending', max_length=30) status = models.CharField(choices=STATUS_CHOICES, default='pending', max_length=30)
class Meta:
ordering = ('id', )
@celery.app.task(name='ImportJob.run', filter=celery.task_method) @celery.app.task(name='ImportJob.run', filter=celery.task_method)
def run(self, replace=False): def run(self, replace=False):
try: try:
......
...@@ -62,7 +62,15 @@ class TrackSerializer(LyricsMixin): ...@@ -62,7 +62,15 @@ class TrackSerializer(LyricsMixin):
tags = TagSerializer(many=True, read_only=True) tags = TagSerializer(many=True, read_only=True)
class Meta: class Meta:
model = models.Track model = models.Track
fields = ('id', 'mbid', 'title', 'artist', 'files', 'tags', 'lyrics') fields = (
'id',
'mbid',
'title',
'artist',
'files',
'tags',
'position',
'lyrics')
class TrackSerializerNested(LyricsMixin): class TrackSerializerNested(LyricsMixin):
artist = ArtistSerializer() artist = ArtistSerializer()
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
</td> </td>
<td colspan="6"> <td colspan="6">
<router-link class="track discrete link" :to="{name: 'library.track', params: {id: track.id }}"> <router-link class="track discrete link" :to="{name: 'library.track', params: {id: track.id }}">
<template v-if="track.position">
{{ track.position }}.
</template>
{{ track.title }} {{ track.title }}
</router-link> </router-link>
</td> </td>
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
</td> </td>
<td colspan="6"> <td colspan="6">
<router-link class="track" :to="{name: 'library.track', params: {id: track.id }}"> <router-link class="track" :to="{name: 'library.track', params: {id: track.id }}">
<template v-if="displayPosition && track.position">
{{ track.position }}.
</template>
{{ track.title }} {{ track.title }}
</router-link> </router-link>
</td> </td>
...@@ -46,7 +49,10 @@ import TrackFavoriteIcon from '@/components/favorites/TrackFavoriteIcon' ...@@ -46,7 +49,10 @@ import TrackFavoriteIcon from '@/components/favorites/TrackFavoriteIcon'
import PlayButton from '@/components/audio/PlayButton' import PlayButton from '@/components/audio/PlayButton'
export default { export default {
props: ['tracks'], props: {
tracks: {type: Array, required: true},
displayPosition: {type: Boolean, default: false}
},
components: { components: {
TrackFavoriteIcon, TrackFavoriteIcon,
PlayButton PlayButton
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
</div> </div>
<div class="ui vertical stripe segment"> <div class="ui vertical stripe segment">
<h2>Tracks</h2> <h2>Tracks</h2>
<track-table v-if="album" :tracks="album.tracks"></track-table> <track-table v-if="album" display-position="true" :tracks="album.tracks"></track-table>
</div> </div>
</template> </template>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment