mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 08:39:24 +02:00
Permissions and db state fixes with new index field
This commit is contained in:
parent
257e67b5a6
commit
e87e2654e8
6 changed files with 148 additions and 20 deletions
|
@ -67,13 +67,18 @@ class Playlist(models.Model):
|
|||
plt.save(update_fields=['index'])
|
||||
return index
|
||||
|
||||
def remove(self, index):
|
||||
existing = self.playlist_tracks.select_for_update()
|
||||
to_update = existing.filter(index__gt=index)
|
||||
return to_update.update(index=models.F('index') - 1)
|
||||
|
||||
|
||||
class PlaylistTrack(models.Model):
|
||||
track = models.ForeignKey(
|
||||
'music.Track',
|
||||
related_name='playlist_tracks',
|
||||
on_delete=models.CASCADE)
|
||||
index = models.PositiveIntegerField(null=True)
|
||||
index = models.PositiveIntegerField(null=True, blank=True)
|
||||
playlist = models.ForeignKey(
|
||||
Playlist, related_name='playlist_tracks', on_delete=models.CASCADE)
|
||||
creation_date = models.DateTimeField(default=timezone.now)
|
||||
|
@ -81,3 +86,12 @@ class PlaylistTrack(models.Model):
|
|||
class Meta:
|
||||
ordering = ('-playlist', 'index')
|
||||
unique_together = ('playlist', 'index')
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
playlist = self.playlist
|
||||
index = self.index
|
||||
update_indexes = kwargs.pop('update_indexes', False)
|
||||
r = super().delete(*args, **kwargs)
|
||||
if index is not None and update_indexes:
|
||||
playlist.remove(index)
|
||||
return r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue