Skip to content

Commit

Permalink
Add some assitive ordering and reprs for objects related to Sponsorsh…
Browse files Browse the repository at this point in the history
…ip years in Django Admin (#2111)
  • Loading branch information
ewdurbin committed Aug 8, 2022
1 parent 723539e commit 0197bd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions sponsors/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ class ProvidedFileAssetConfigurationInline(StackedPolymorphicInline.Child):
class SponsorshipBenefitAdmin(PolymorphicInlineSupportMixin, OrderedModelAdmin):
change_form_template = "sponsors/admin/sponsorshipbenefit_change_form.html"
inlines = [BenefitFeatureConfigurationInline]
ordering = ("program", "order")
ordering = ("-year", "program", "order")
list_display = [
"program",
"year",
"short_name",
"package_only",
"internal_value",
Expand Down Expand Up @@ -170,7 +171,7 @@ def update_related_sponsorships(self, *args, **kwargs):

@admin.register(SponsorshipPackage)
class SponsorshipPackageAdmin(OrderedModelAdmin):
ordering = ("order",)
ordering = ("-year", "order",)
list_display = ["name", "year", "advertise", "move_up_down_links"]
list_filter = ["advertise", "year"]
search_fields = ["name"]
Expand All @@ -197,8 +198,8 @@ class SponsorContactInline(admin.TabularInline):

class SponsorshipsInline(admin.TabularInline):
model = Sponsorship
fields = ["link", "status", "applied_on", "start_date", "end_date"]
readonly_fields = ["link", "status", "applied_on", "start_date", "end_date"]
fields = ["link", "status", "year", "applied_on", "start_date", "end_date"]
readonly_fields = ["link", "status", "year", "applied_on", "start_date", "end_date"]
can_delete = False
extra = 0

Expand Down
10 changes: 5 additions & 5 deletions sponsors/models/sponsorship.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class SponsorshipPackage(OrderedModel):
year = models.PositiveIntegerField(null=True, validators=YEAR_VALIDATORS, db_index=True)

def __str__(self):
return self.name
return f'{self.name} ({self.year})'

class Meta(OrderedModel.Meta):
pass
class Meta:
ordering = ('-year', 'order',)

def has_user_customization(self, benefits):
"""
Expand Down Expand Up @@ -199,7 +199,7 @@ def user_customizations(self):
return self.package.get_user_customization(benefits)

def __str__(self):
repr = f"{self.level_name} ({self.get_status_display()}) for sponsor {self.sponsor.name}"
repr = f"{self.level_name} - {self.year} - ({self.get_status_display()}) for sponsor {self.sponsor.name}"
if self.start_date and self.end_date:
fmt = "%m/%d/%Y"
start = self.start_date.strftime(fmt)
Expand Down Expand Up @@ -498,7 +498,7 @@ def related_sponsorships(self):
return Sponsorship.objects.filter(id__in=Subquery(ids_qs))

def __str__(self):
return f"{self.program} > {self.name}"
return f"{self.program} > {self.name} ({self.year})"

def _short_name(self):
return truncatechars(self.name, 42)
Expand Down

0 comments on commit 0197bd5

Please sign in to comment.