Skip to content

Commit

Permalink
Merge pull request #3259 from webkom/migrate_authors
Browse files Browse the repository at this point in the history
Merge data from "created_by" to "authors" field
  • Loading branch information
jonasdeluna committed Mar 26, 2023
2 parents 2da309f + 67aa136 commit 58011a0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lego/apps/articles/fixtures/development_articles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
- lorem
- ipsum
- sample-text
created_by_id: 1
authors: [1]

- model: articles.Article
pk: 2
Expand All @@ -58,6 +60,8 @@
tags:
- lorem
- ipsum
created_by_id: 1
authors: [1]

- model: articles.Article
pk: 3
Expand All @@ -81,6 +85,8 @@
- lorem
- ipsum
youtube_url: https://www.youtube.com/watch?v=bLHL75H_VEM
created_by_id: 1
authors: [1]

- model: articles.Article
pk: 4
Expand All @@ -102,6 +108,8 @@
- - Users
tags:
- weekly
created_by_id: 1
authors: [1]

- model: articles.Article
pk: 5
Expand All @@ -124,6 +132,8 @@
tags:
- lorem
- ipsum
created_by_id: 1
authors: [1]

- model: articles.Article
pk: 6
Expand All @@ -145,3 +155,5 @@
tags:
- lorem
- ipsum
created_by_id: 1
authors: [1]
4 changes: 4 additions & 0 deletions lego/apps/articles/fixtures/test_articles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
fields:
title: faget get rekt
created_by: 1
authors: [1]
description: much good
text: >
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
Expand All @@ -20,6 +21,7 @@
fields:
title: Ikkje løye det!
created_by: 1
authors: [1]
description: Om du e Tore?
text: Tore Tang, en gammal mann. Hele webkom kjenner han.
can_view_groups:
Expand All @@ -30,6 +32,7 @@
fields:
title: Alle kan se!
created_by: 1
authors: [1]
description: Håper jeg ..
text: huehehehuuehhuehuehuehuehue
require_auth: False
Expand All @@ -39,6 +42,7 @@
fields:
title: Ukens Weekly
created_by: 1
authors: [1]
description: Skjedd sykt mye bra denne uken
text: >
HS har snakket om at de skal få flere daljer, backup har
Expand Down
24 changes: 24 additions & 0 deletions lego/apps/articles/migrations/0012_migrate_authors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.0.9 on 2023-03-16 13:13

from django.conf import settings
from django.db import migrations


def merge_authors(apps, schema_editor):
Article = apps.get_model("articles", "Article")
for e in Article.objects.all():
if e.created_by != None and e.authors == None:
e.authors.add(e.created_by)
e.save()


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("articles", "0011_article_authors"),
]

operations = [
migrations.RunPython(merge_authors),
]

0 comments on commit 58011a0

Please sign in to comment.