diff --git a/artists/admin.py b/artists/admin.py index 65e133c..45a5786 100644 --- a/artists/admin.py +++ b/artists/admin.py @@ -1,8 +1,9 @@ from django.contrib import admin +from simple_history.admin import SimpleHistoryAdmin from .models import Artist, JamendoArtist, MagnatuneArtist -admin.site.register(Artist) +admin.site.register(Artist, SimpleHistoryAdmin) admin.site.register(JamendoArtist) admin.site.register(MagnatuneArtist) diff --git a/artists/migrations/0008_historicalartist_historicalhyperlink.py b/artists/migrations/0008_historicalartist_historicalhyperlink.py new file mode 100644 index 0000000..3fae544 --- /dev/null +++ b/artists/migrations/0008_historicalartist_historicalhyperlink.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import django.utils.timezone +import model_utils.fields +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('artists', '0007_auto_20140923_0804'), + ] + + operations = [ + migrations.CreateModel( + name='HistoricalArtist', + fields=[ + ('id', models.IntegerField(db_index=True, auto_created=True, verbose_name='ID', blank=True)), + ('created', model_utils.fields.AutoCreatedField(verbose_name='created', editable=False, default=django.utils.timezone.now)), + ('modified', model_utils.fields.AutoLastModifiedField(verbose_name='modified', editable=False, default=django.utils.timezone.now)), + ('name', models.CharField(db_index=True, max_length=100)), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('history_user', models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True)), + ], + options={ + 'verbose_name': 'historical artist', + 'ordering': ('-history_date', '-history_id'), + }, + bases=(models.Model,), + ), + migrations.CreateModel( + name='HistoricalHyperlink', + fields=[ + ('id', models.IntegerField(db_index=True, auto_created=True, verbose_name='ID', blank=True)), + ('created', model_utils.fields.AutoCreatedField(verbose_name='created', editable=False, default=django.utils.timezone.now)), + ('modified', model_utils.fields.AutoLastModifiedField(verbose_name='modified', editable=False, default=django.utils.timezone.now)), + ('order', models.IntegerField()), + ('artist_id', models.IntegerField(db_index=True, blank=True, null=True)), + ('name', models.CharField(choices=[('bandcamp', 'Bandcamp'), ('jamendo', 'Jamendo'), ('magnatune', 'Magnatune'), ('fma', 'Free Music Archive'), ('homepage', 'Homepage')], max_length=50)), + ('url', models.URLField()), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('history_user', models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True)), + ], + options={ + 'verbose_name': 'historical hyperlink', + 'ordering': ('-history_date', '-history_id'), + }, + bases=(models.Model,), + ), + ] diff --git a/artists/models.py b/artists/models.py index cb31d7f..342e94b 100644 --- a/artists/models.py +++ b/artists/models.py @@ -2,6 +2,7 @@ import jsonfield from model_utils import Choices from model_utils.models import TimeStampedModel +from simple_history.models import HistoricalRecords from .managers import ArtistManager @@ -12,6 +13,7 @@ class Artist(TimeStampedModel): name = models.CharField(max_length=100, unique=True) objects = ArtistManager() + history = HistoricalRecords() class Meta: ordering = ('name',) @@ -36,6 +38,7 @@ class Hyperlink(TimeStampedModel): artist = models.ForeignKey(Artist, related_name='links') name = models.CharField(max_length=50, choices=NAMES) url = models.URLField() + history = HistoricalRecords() class Meta: ordering = ('order',) diff --git a/artists/views.py b/artists/views.py index 0715f54..1be8b8e 100644 --- a/artists/views.py +++ b/artists/views.py @@ -20,3 +20,7 @@ def get_queryset(self): else: qs = super().get_queryset() return qs[:100] + + def pre_save(self, obj): + # set the user making a change for simple_history to track + obj._history_user = self.request.user diff --git a/freemusicninja/settings.py b/freemusicninja/settings.py index e4bb906..5aea86c 100644 --- a/freemusicninja/settings.py +++ b/freemusicninja/settings.py @@ -49,6 +49,7 @@ 'djangosecure', 'rest_framework', 'rest_framework.authtoken', + 'simple_history', 'artists', 'echonest', diff --git a/requirements.txt b/requirements.txt index 3bf8d17..13b8c4a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ django-cors-headers==0.13 django-filter==0.7 django-jsonfield==0.9.13 django-model-utils==2.2.0 +django-simple-history==1.5.2 djangorestframework==2.4.2 psycopg2==2.5.4 purl==1.0