Skip to content

Commit ce8985b

Browse files
committed
Add updated_at and sort so oldest is picked first
1 parent 6812b26 commit ce8985b

3 files changed

Lines changed: 24 additions & 13 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.21 on 2025-06-22 17:38
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('teams', '0068_alter_teamshift_team_members'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='teamshiftassignment',
15+
name='updated_at',
16+
field=models.DateTimeField(auto_now=True),
17+
),
18+
]

src/teams/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ class TeamShiftAssignment(CampRelatedModel):
573573
help_text="Is the shift assignment for sale?",
574574
)
575575

576+
updated_at = models.DateTimeField(auto_now=True)
577+
576578
@property
577579
def camp(self) -> Camp:
578580
"""All CampRelatedModels must have a camp FK or a camp property."""

src/teams/views/shifts.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)