StaticField for non-changing text data in forms

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class NoInput(forms.Widget):
    def render(self, name, value, attrs=None):
        return mark_safe(value)

class StaticField(forms.Field):
    
    widget = NoInput
    
    def clean(self, value):
        return 

# Example usage
#class OnlyTextForm(forms.ModelForm):
#    
#    points = StaticField(label=_('Points'))
#    reviewer = StaticField(label=_('Reviewer'))
#    
#    def clean(self):
#        for name, field in self.fields.items():
#            if isinstance(field, StaticField):
#                self.cleaned_data.update({name: self.initial[name]})
#
#        return self.cleaned_data

More like this

  1. Multiple-Submit-Button Widget for Choice Field by Archatas 4 years, 9 months ago
  2. ImageField for admin with thumbnail by semente 3 years, 11 months ago
  3. BetterForm with fieldsets and row_attrs by carljm 4 years, 3 months ago
  4. boostrap prepend-input for widgets by DimmuR 7 months, 3 weeks ago
  5. boostrap append-input for widgets by DimmuR 7 months, 3 weeks ago

Comments

(Forgotten your password?)