File tree Expand file tree Collapse file tree 1 file changed +29
-6
lines changed Expand file tree Collapse file tree 1 file changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -1126,12 +1126,35 @@ def unwatch(self, episode_number):
1126
1126
)
1127
1127
1128
1128
if episode .repeats > 0 :
1129
- episode .repeats -= 1
1130
- episode .save (update_fields = ["repeats" ])
1131
- logger .info (
1132
- "%s watch count decreased." ,
1133
- episode ,
1134
- )
1129
+ # Get the historical records for this episode
1130
+ history = episode .history .all ()
1131
+
1132
+ if history .count () > 1 :
1133
+ # Get the previous historical record (second latest)
1134
+ previous_record = history [1 ]
1135
+
1136
+ # Revert to previous state without creating new history
1137
+ episode .repeats = previous_record .repeats
1138
+ episode .end_date = previous_record .end_date
1139
+ episode .save_without_historical_record ()
1140
+
1141
+ # Delete the latest historical record (the one we're reverting from)
1142
+ latest_record = history .first ()
1143
+ latest_record .delete ()
1144
+
1145
+ logger .info (
1146
+ "%s reverted to previous state (repeats: %s)" ,
1147
+ episode ,
1148
+ episode .repeats ,
1149
+ )
1150
+ else :
1151
+ # Fallback to original behavior if no previous history exists
1152
+ episode .repeats -= 1
1153
+ episode .save_without_historical_record (update_fields = ["repeats" ])
1154
+ logger .info (
1155
+ "%s watch count decreased (no history to revert)." ,
1156
+ episode ,
1157
+ )
1135
1158
else :
1136
1159
episode .delete ()
1137
1160
logger .info (
You can’t perform that action at this time.
0 commit comments