Add data migration

This commit is contained in:
Christian Cueni 2020-07-01 16:24:46 +02:00
parent 4944745da0
commit 1045093cac
4 changed files with 36 additions and 8 deletions

View File

@ -20,16 +20,16 @@ MYSKILLBOX_LICENSES = {
'duration': 365,
'name': 'Student 1 year'
},
"978-3-0355-1861-0": {
'edition': TEACHER_KEY,
'duration': 30,
'name': 'Teacher test 1 month'
},
"978-3-0355-1862-7": {
'edition': STUDENT_KEY,
'duration': 30,
'name': 'Student test 1 month'
},
"978-3-0355-1861-0": {
'edition': TEACHER_KEY,
'duration': 30,
'name': 'Teacher test 1 month'
},
"978-3-0355-1823-8": {
'edition': TEACHER_KEY,
'duration': 365,

View File

@ -72,6 +72,6 @@ class UserSettingAdmin(admin.ModelAdmin):
@admin.register(License)
class LicenseAdmin(admin.ModelAdmin):
list_display = ('licensee',)
list_filter = ('licensee',)
list_display = ('licensee', 'for_role', 'expire_date', 'isbn')
list_filter = ('licensee', 'expire_date')
raw_id_fields = ('licensee',)

View File

@ -2,7 +2,6 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [

View File

@ -0,0 +1,29 @@
# Generated by Django 2.1.15 on 2020-07-01 13:42
from django.db import migrations
from users.managers import RoleManager
STUDENT_4Y_ISBN = '978-3-0355-1397-4'
TEACHER_1Y_ISBN = '978-3-0355-1823-8'
def add_isbn_to_license(apps, schema_editor):
License = apps.get_model('users', 'License')
for existing_license in License.objects.all():
if existing_license.for_role.key == RoleManager.TEACHER_KEY:
existing_license.isbn = TEACHER_1Y_ISBN
else:
existing_license.isbn = STUDENT_4Y_ISBN
existing_license.save()
class Migration(migrations.Migration):
dependencies = [
('users', '0020_license_isbn'),
]
operations = [
migrations.RunPython(add_isbn_to_license, migrations.RunPython.noop),
]