Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge data from "created_by" to "authors" field #3259

Merged
merged 1 commit into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
jonasdeluna marked this conversation as resolved.
Show resolved Hide resolved
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should't this be e.authors != None, or can you do .add() anyways?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed to run fine for me. From testing in shell, the field is None if there's no entries and adding still works.

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),
]