Created
February 14, 2025 22:16
-
-
Save bmispelon/243425a4ed2dc3d03adb0cedf000940a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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