|
1 | 1 | # Generated by Django 4.2.3 on 2023-07-20 18:34 |
| 2 | +import os |
2 | 3 |
|
3 | 4 | from django.db import migrations |
4 | 5 | from django.db.migrations import RunPython |
5 | 6 |
|
6 | 7 |
|
7 | 8 | def project_news_to_news_news(apps, schema_editor): |
8 | | - # add ProjectNews model to news app via schema_editor |
9 | 9 | ProjectNews = apps.get_model("projects.ProjectNews") |
10 | 10 | News = apps.get_model("news", "News") |
11 | 11 | ContentType = apps.get_model("contenttypes", "ContentType") |
12 | | - project_content_type = ContentType.objects.get( |
13 | | - app_label="projects", model="project" |
14 | | - ) |
| 12 | + content_type_count = ContentType.objects.all().count() |
| 13 | + if content_type_count == 0: |
| 14 | + return |
| 15 | + |
15 | 16 | project_news_content_type = ContentType.objects.get( |
16 | 17 | app_label="projects", model="projectnews" |
17 | 18 | ) |
| 19 | + project_content_type = ContentType.objects.get( |
| 20 | + app_label="projects", model="project" |
| 21 | + ) |
| 22 | + |
18 | 23 | news_content_type = ContentType.objects.get(app_label="news", model="news") |
19 | 24 | Like = apps.get_model("core", "Like") |
20 | 25 | View = apps.get_model("core", "View") |
@@ -50,7 +55,9 @@ class Migration(migrations.Migration): |
50 | 55 |
|
51 | 56 | dependencies = [ |
52 | 57 | ("news", "0006_alter_news_options_remove_news_cover_url_and_more"), |
53 | | - ("projects", "0013_projectnews") |
| 58 | + ("projects", "0013_projectnews"), |
| 59 | + ("projects", "0001_initial"), |
| 60 | + ("projects", "0002_initial"), |
54 | 61 | ] |
55 | 62 |
|
56 | 63 | operations = [ |
|
0 commit comments