@@ -30,25 +30,38 @@ def create_DAB_contenttypes(
3030 comes from the permission registry.
3131 """
3232 DABContentType = apps .get_model ("dab_rbac" , "DABContentType" )
33+ ContentType = apps .get_model ("contenttypes" , "ContentType" )
3334
3435 content_types = get_local_DAB_contenttypes (using , DABContentType )
3536
3637 # TODO: add api_slug field when added
37- cts = []
38+ ct_data = []
3839 for model in permission_registry .all_registered_models :
3940 service = get_resource_prefix (model )
4041 if (service , model ._meta .model_name ) not in content_types :
4142 # The content type is not seen in existing entries, add to list for creation
42- cts .append (
43- DABContentType (
44- service = service ,
45- app_label = model ._meta .app_label ,
46- model = model ._meta .model_name ,
47- )
43+ ct_item_data = dict (
44+ service = service ,
45+ app_label = model ._meta .app_label ,
46+ model = model ._meta .model_name ,
4847 )
49- if not cts :
48+ # To make usage earier in a transitional period, we will set the content type
49+ # of any new entries created here to the id of its corresponding ContentType
50+ # from the actual contenttypes app, allowing many filters to work
51+ real_ct = ContentType .objects .get_for_model (model )
52+ if not DABContentType .objects .filter (id = real_ct .id ).exists ():
53+ ct_item_data ['id' ] = real_ct .id
54+ ct_data .append (ct_item_data )
55+ if not ct_data :
5056 return
51- DABContentType .objects .using (using ).bulk_create (cts )
57+
58+ # To make usage earier in a transitional period, we will set the content type
59+ # of any new entries created here to the id of its corresponding ContentType
60+ # from the actual contenttypes app, allowing many filters to work
61+ cts = []
62+ for ct_item_data in ct_data :
63+ cts .append (DABContentType .objects .create (** ct_item_data ))
64+
5265 if verbosity >= 2 :
5366 for ct in cts :
5467 logger .debug ("Adding DAB content type " f"'{ ct .service } :{ ct .app_label } | { ct .model } '" )
0 commit comments