@@ -59,26 +59,36 @@ def get(self, *args, **kwargs):
5959
6060class DevScript (CreateAPIView ):
6161 def create (self , request ):
62- content_type = ContentType .objects .filter (model = "project" ).first ()
62+ content_type_project = ContentType .objects .filter (model = "project" ).first ()
6363 for project in Project .objects .filter (draft = False ):
6464 if not News .objects .filter (
65- content_type = content_type , object_id = project .id
65+ content_type = content_type_project , object_id = project .id
6666 ).exists ():
6767 News .objects .create (
68- content_type = content_type ,
68+ content_type = content_type_project ,
6969 object_id = project .id ,
7070 datetime_created = project .datetime_created ,
7171 )
7272
73- content_type = ContentType .objects .filter (model = "vacancy" ).first ()
73+ content_type_vacancy = ContentType .objects .filter (model = "vacancy" ).first ()
7474 for vacancy in Vacancy .objects .filter (is_active = True ):
7575 if not News .objects .filter (
76- content_type = content_type , object_id = vacancy .id
76+ content_type = content_type_vacancy , object_id = vacancy .id
7777 ).exists ():
7878 News .objects .create (
79- content_type = content_type ,
79+ content_type = content_type_vacancy ,
8080 object_id = vacancy .id ,
8181 datetime_created = vacancy .datetime_created ,
8282 )
8383
84+ news_to_delete = list (
85+ News .objects .filter (
86+ content_type__in = [content_type_vacancy , content_type_project ]
87+ )
88+ )
89+
90+ for news in news_to_delete :
91+ if not news .content_object :
92+ news .delete ()
93+
8494 return Response ({"status" : "success" }, status = 201 )
0 commit comments