File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change 3636
3737
3838def PROTECT_IF_PUBLIC_VERSION (collector , field , sub_objs , using ):
39- state = sub_objs [0 ].state # State of the first version in sub_objs
40- if state == constants .PUBLISHED :
41- models .PROTECT (collector , field , sub_objs , using )
39+ public_exists = sub_objs .filter (state = constants .PUBLISHED )
40+ if public_exists :
41+ # Any public objects?
42+ raise models .ProtectedError (
43+ f"Cannot delete some instances of model '{ field .remote_field .model .__name__ } ' because they are "
44+ f"referenced through a protected foreign key: '{ sub_objs [0 ].__class__ .__name__ } .{ field .name } '" ,
45+ public_exists ,
46+ )
4247 models .SET_NULL (collector , field , sub_objs , using )
4348
4449
@@ -142,7 +147,14 @@ class Meta:
142147 )
143148
144149 def __str__ (self ):
145- return f"Version #{ self .pk } "
150+ state = dict (constants .VERSION_STATES ).get (self .state , self .state )
151+ if self .object_id :
152+ try :
153+ return f"Version #{ self .pk } ({ state } ) of { self .content } "
154+ except Exception :
155+ # In case the content object cannot be stringified
156+ pass
157+ return f"Version #{ self .pk } ({ state } )"
146158
147159 def verbose_name (self ):
148160 return _ ("Version #{number} ({state} {date})" ).format (
You can’t perform that action at this time.
0 commit comments