Skip to content

Commit

Permalink
add Pot custom form
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed May 20, 2024
1 parent 6456274 commit eeeb00e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pots/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,32 @@ def get_form(self, request, obj=None, **kwargs):
return form


class PotForm(forms.ModelForm):
class Meta:
model = Pot
fields = "__all__"

def __init__(self, *args, **kwargs):
super(PotForm, self).__init__(*args, **kwargs)
# Ensure self.instance is available before accessing it
if self.instance.pk:
# Set the queryset for the admins field to only include relevant accounts
self.fields["admins"].queryset = self.instance.admins.all()


@admin.register(Pot)
class PotAdmin(admin.ModelAdmin):
form = PotForm
list_display = ("id", "pot_factory", "deployer", "deployed_at", "name")
search_fields = ("id", "name", "deployer__id")
list_filter = ("deployed_at",)

def get_form(self, request, obj=None, **kwargs):
form = super(PotAdmin, self).get_form(request, obj, **kwargs)
if obj:
form.base_fields["admins"].queryset = obj.admins.all()
return form


@admin.register(PotApplication)
class PotApplicationAdmin(admin.ModelAdmin):
Expand Down

0 comments on commit eeeb00e

Please sign in to comment.