diff --git a/api/funkwhale_api/history/admin.py b/api/funkwhale_api/history/admin.py index 6d0480e73b4209629499c7ae26b8c5efa8348999..5ddfb899848f389d776632eaf9e3b6d389cd7f58 100644 --- a/api/funkwhale_api/history/admin.py +++ b/api/funkwhale_api/history/admin.py @@ -4,7 +4,7 @@ from . import models @admin.register(models.Listening) class ListeningAdmin(admin.ModelAdmin): - list_display = ['track', 'end_date', 'user', 'session_key'] + list_display = ['track', 'creation_date', 'user', 'session_key'] search_fields = ['track__name', 'user__username'] list_select_related = [ 'user', diff --git a/api/funkwhale_api/history/migrations/0002_auto_20180325_1433.py b/api/funkwhale_api/history/migrations/0002_auto_20180325_1433.py new file mode 100644 index 0000000000000000000000000000000000000000..d83dbb0a466b668279619e53406b8ae977ab5dc7 --- /dev/null +++ b/api/funkwhale_api/history/migrations/0002_auto_20180325_1433.py @@ -0,0 +1,22 @@ +# Generated by Django 2.0.3 on 2018-03-25 14:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('history', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='listening', + options={'ordering': ('-creation_date',)}, + ), + migrations.RenameField( + model_name='listening', + old_name='end_date', + new_name='creation_date', + ), + ] diff --git a/api/funkwhale_api/history/models.py b/api/funkwhale_api/history/models.py index 56310ddc0d2546784bed02952fe6142a2d139858..762d5bf7b2cf66bdd9a96325c630db65a53ddaae 100644 --- a/api/funkwhale_api/history/models.py +++ b/api/funkwhale_api/history/models.py @@ -6,7 +6,8 @@ from funkwhale_api.music.models import Track class Listening(models.Model): - end_date = models.DateTimeField(default=timezone.now, null=True, blank=True) + creation_date = models.DateTimeField( + default=timezone.now, null=True, blank=True) track = models.ForeignKey( Track, related_name="listenings", on_delete=models.CASCADE) user = models.ForeignKey( @@ -18,7 +19,7 @@ class Listening(models.Model): session_key = models.CharField(max_length=100, null=True, blank=True) class Meta: - ordering = ('-end_date',) + ordering = ('-creation_date',) def save(self, **kwargs): if not self.user and not self.session_key: diff --git a/api/funkwhale_api/history/serializers.py b/api/funkwhale_api/history/serializers.py index 7a2280cea2a236357982f309b7218c3e0d073299..8fe6fa6e01f07a395f2c337ea45591bd315a03d3 100644 --- a/api/funkwhale_api/history/serializers.py +++ b/api/funkwhale_api/history/serializers.py @@ -12,7 +12,7 @@ class ListeningActivitySerializer(activity_serializers.ModelSerializer): type = serializers.SerializerMethodField() object = TrackActivitySerializer(source='track') actor = UserActivitySerializer(source='user') - published = serializers.DateTimeField(source='end_date') + published = serializers.DateTimeField(source='creation_date') class Meta: model = models.Listening @@ -36,7 +36,7 @@ class ListeningSerializer(serializers.ModelSerializer): class Meta: model = models.Listening - fields = ('id', 'user', 'session_key', 'track', 'end_date') + fields = ('id', 'user', 'session_key', 'track', 'creation_date') def create(self, validated_data): diff --git a/api/tests/history/test_activity.py b/api/tests/history/test_activity.py index b5ab07b8235f12045f5ee1b9fba3fce0c3da57d5..04000604b264394ab7c3c1425e49a1f2b59bff71 100644 --- a/api/tests/history/test_activity.py +++ b/api/tests/history/test_activity.py @@ -23,7 +23,7 @@ def test_activity_listening_serializer(factories): "id": listening.get_activity_url(), "actor": actor, "object": TrackActivitySerializer(listening.track).data, - "published": field.to_representation(listening.end_date), + "published": field.to_representation(listening.creation_date), } data = serializers.ListeningActivitySerializer(listening).data