Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion artists/admin.py
Original file line number Diff line number Diff line change
@@ -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)
57 changes: 57 additions & 0 deletions artists/migrations/0008_historicalartist_historicalhyperlink.py
Original file line number Diff line number Diff line change
@@ -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,),
),
]
3 changes: 3 additions & 0 deletions artists/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -12,6 +13,7 @@ class Artist(TimeStampedModel):

name = models.CharField(max_length=100, unique=True)
objects = ArtistManager()
history = HistoricalRecords()

class Meta:
ordering = ('name',)
Expand All @@ -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',)
Expand Down
4 changes: 4 additions & 0 deletions artists/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions freemusicninja/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'djangosecure',
'rest_framework',
'rest_framework.authtoken',
'simple_history',

'artists',
'echonest',
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down