Skip to content

Instantly share code, notes, and snippets.

@bmispelon
Created February 14, 2025 22:16
Show Gist options
  • Save bmispelon/243425a4ed2dc3d03adb0cedf000940a to your computer and use it in GitHub Desktop.
Save bmispelon/243425a4ed2dc3d03adb0cedf000940a to your computer and use it in GitHub Desktop.
class Release(models.Model):
... # a lot of fields
tarball = models.FileField(blank=True)
wheel = models.FileField(blank=True)
checksum = models.FileField(blank=True)
class ReleaseAdmin(admin.ModelAdmin):
# What I want is for the fields tarball, wheel and checksum to be optional
# on the model, but required in the admin form
def get_form(self, request, obj=None, **kwargs):
form_class = super().get_form(request, obj=obj, **kwargs)
class ReleaseModelForm(form_class):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for artefact_field in ["tarball", "wheel", "checksum"]:
self.fields[artefact_field].required = True
return ReleaseModelForm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment