Last active
November 9, 2021 10:15
-
-
Save UnknownPlatypus/76bbd42a57fa299cbfe44547b905242d 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
from django.db import models | |
from django.forms import Textarea | |
class HowToItemInline(admin.StackedInline): | |
# All fields of a particular type | |
formfield_overrides = { | |
models.TextField: {"widget": Textarea(attrs={"rows": 1, "cols": 80})}, | |
} | |
# Specific fields | |
wide_charfields = ["field1", "field2"] | |
def get_formset(self, request, obj=None, **kwargs): | |
formset = super().get_formset(request, obj, **kwargs) | |
for field in self.wide_charfields: | |
formset.form.base_fields[field].widget = Textarea(attrs={"rows": 2, "cols": 80}) | |
return formset | |
class HowToAdmin(admin.ModelAdmin): | |
# All fields of a particular type | |
formfield_overrides = { | |
models.TextField: {"widget": Textarea(attrs={"rows": 1, "cols": 80})}, | |
} | |
# Specific fields | |
wide_charfields = ["field1", "field2"] | |
def get_form(self, request, obj=None, **kwargs): | |
form = super().get_form(request, obj, **kwargs) | |
for field in self.wide_charfields: | |
form.base_fields[field].widget = Textarea(attrs={"rows": 1, "cols": 80}) | |
return form |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment