1 # Generated by Django 4.0.8 on 2025-07-14 13:40
3 from django.db import migrations
4 from django.utils.timezone import now
7 def move_sets_to_userlists(apps, schema_editor):
8 UserList = apps.get_model('social', 'UserList')
9 UserListItem = apps.get_model('social', 'UserListItem')
10 Tag = apps.get_model('catalogue', 'Tag')
12 for tag in Tag.objects.filter(category='set'):
15 ul = UserList.objects.create(
19 favorites=not tag.name,
21 created_at=tag.created_at,
22 updated_at=tag.changed_at,
25 for i, item in enumerate(tag.items.all()):
26 #assert item.content_type_id == 12, item.content_type_id
28 ul.userlistitem_set.create(
30 created_at=ul.updated_at,
31 updated_at=ul.updated_at,
32 book_id=item.object_id
38 def rollback_userlists_to_sets(apps, schema_editor):
39 UserList = apps.get_model('social', 'UserList')
40 UserListItem = apps.get_model('social', 'UserListItem')
41 Tag = apps.get_model('catalogue', 'Tag')
44 class Migration(migrations.Migration):
47 ('social', '0020_userlist_userlistitem'),
48 ('catalogue', '0001_initial'),
53 move_sets_to_userlists,
54 rollback_userlists_to_sets