-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
58 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
integreat_cms/cms/migrations/0109_migrate_contact_data_from_poi_to_contacts_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Generated by Django 4.2.16 on 2024-11-06 12:57 | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
from django.db import migrations | ||
|
||
if TYPE_CHECKING: | ||
from django.apps.registry import Apps | ||
|
||
|
||
def create_primary_contact(apps: Apps) -> None: | ||
""" | ||
Create primary contact from the poi contact data | ||
:param apps: The configuration of installed applications | ||
""" | ||
POI = apps.get_model("cms", "POI") | ||
Contact = apps.get_model("cms", "Contact") | ||
for poi in POI.objects.all(): | ||
if poi.email or poi.phone_number or poi.website: | ||
primary_contact = Contact.objects.create( | ||
primary_email=poi.email, | ||
primary_phone_number=poi.phone_number, | ||
primary_website=poi.website, | ||
point_of_contact_for="", | ||
name="", | ||
location=poi, | ||
) | ||
primary_contact.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
""" | ||
Migrate contact data from poi to contacts model | ||
""" | ||
|
||
dependencies = [ | ||
("cms", "0108_rename_contact_title_to_point_of_contact_for"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_primary_contact), | ||
migrations.RemoveField( | ||
model_name="poi", | ||
name="email", | ||
), | ||
migrations.RemoveField( | ||
model_name="poi", | ||
name="phone_number", | ||
), | ||
migrations.RemoveField( | ||
model_name="poi", | ||
name="website", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters