@@ -9,20 +9,41 @@ def project_news_to_news_news(apps, schema_editor):
99 ProjectNews = apps .get_model ("projects.ProjectNews" )
1010 News = apps .get_model ("news" , "News" )
1111 ContentType = apps .get_model ("contenttypes" , "ContentType" )
12+ project_content_type = ContentType .objects .get (
13+ app_label = "projects" , model = "project"
14+ )
15+ project_news_content_type = ContentType .objects .get (
16+ app_label = "projects" , model = "projectnews"
17+ )
18+ news_content_type = ContentType .objects .get (app_label = "news" , model = "news" )
19+ Like = apps .get_model ("core" , "Like" )
20+ View = apps .get_model ("core" , "View" )
1221 for project_news in ProjectNews .objects .all ():
13- project_content_type = ContentType .objects .get (
14- app_label = "projects" , model = "project"
15- )
16- News .objects .create (
22+ obj = News .objects .create (
1723 text = project_news .text ,
1824 content_type = project_content_type ,
1925 object_id = project_news .project .id ,
20- files = project_news .files .all (),
21- views = project_news .views .all (),
22- likes = project_news .likes .all (),
2326 datetime_created = project_news .datetime_created ,
2427 datetime_updated = project_news .datetime_updated
2528 )
29+ obj .files .set (project_news .files .all ())
30+ likes = Like .objects .filter (
31+ content_type = project_news_content_type ,
32+ object_id = project_news .id ,
33+ )
34+ views = View .objects .filter (
35+ content_type = project_news_content_type ,
36+ object_id = project_news .id ,
37+ )
38+ for i in likes :
39+ i .content_type = news_content_type
40+ i .object_id = obj .id
41+ i .save ()
42+ for i in views :
43+ i .content_type = news_content_type
44+ i .object_id = obj .id
45+ i .save ()
46+ obj .save ()
2647
2748
2849class Migration (migrations .Migration ):
@@ -33,5 +54,5 @@ class Migration(migrations.Migration):
3354 ]
3455
3556 operations = [
36- RunPython (project_news_to_news_news )
57+ RunPython (project_news_to_news_news , reverse_code = migrations . RunPython . noop )
3758 ]
0 commit comments