@@ -324,10 +324,7 @@ def get_context_data(self, **kwargs) -> dict[str, object]:
324324 """Method for setting the page context data."""
325325 context = super ().get_context_data (** kwargs )
326326 context ['action' ] = f"Are you sure you want to take this { self .object } ?"
327- context ["team" ] = Team .objects .get (
328- camp = self .camp ,
329- slug = self .kwargs ["team_slug" ],
330- )
327+ context ["team" ] = self .object .team
331328 return context
332329
333330 def form_valid (self , form : ModelForm [TeamShift ]) -> HttpResponseRedirect :
@@ -359,7 +356,7 @@ def form_valid(self, form: ModelForm[TeamShift]) -> HttpResponseRedirect:
359356 else :
360357 # Remove at most one shift assignment for sale if any
361358 # When a shift is for sale and a user presses assign its first assigning the for sale one
362- for shift_assignment in shift .team_members .filter (teamshiftassignment__for_sale = True )[:1 ]:
359+ for shift_assignment in shift .team_members .filter (teamshiftassignment__for_sale = True ). order_by ( 'teamshiftassignment__updated_at' ) [:1 ]:
363360 shift .team_members .remove (shift_assignment )
364361 shift .team_members .add (team_member )
365362
@@ -380,10 +377,7 @@ def get_context_data(self, **kwargs) -> dict[str, object]:
380377 """Method for setting the page context data."""
381378 context = super ().get_context_data (** kwargs )
382379 context ['action' ] = f"Are you sure you want to drop this { self .object } ?"
383- context ["team" ] = Team .objects .get (
384- camp = self .camp ,
385- slug = self .kwargs ["team_slug" ],
386- )
380+ context ["team" ] = self .object .team
387381 return context
388382
389383 def form_valid (self , form : ModelForm [TeamShift ]) -> HttpResponseRedirect :
@@ -412,10 +406,7 @@ def get_context_data(self, **kwargs) -> dict[str, object]:
412406 """Method for setting the page context data."""
413407 context = super ().get_context_data (** kwargs )
414408 context ['action' ] = f"Are you sure you want to this { self .object } available to others?"
415- context ["team" ] = Team .objects .get (
416- camp = self .camp ,
417- slug = self .kwargs ["team_slug" ],
418- )
409+ context ["team" ] = self .object .team
419410 return context
420411
421412 http_methods = ("get" ,)
0 commit comments