Sorry but I don't understand. For me, what you say now is that you want the field to be visible but empty (without any data from model in it) or invisible (excluded)? Can you, please, clarify what do you want to achieve? Have you tried appending the lines I gave you, not replacing the last line? (both disabled and readonly)
W dniu środa, 19 września 2018 15:47:16 UTC+2 użytkownik nelson fernando garcia gomez napisał: > > This only disables it but internally it receives data this makes the > process of loading the template is the same with disabled enabled or > disabled, so it is necessary to use readonly but does not show readonly. > > > El martes, 18 de septiembre de 2018, 19:00:37 (UTC-5), Mateusz escribió: >> >> (use traductor si necesita) >> >> I hope I understand your question correctly. >> >> When in Django 1.8 or 1.9+ you can just do >> self.fields['destination'].disabled = True >> >> in lower versions you should add >> self.fields['destination'].widget.attrs['disabled'] = True >> at the end of your __init__(..). >> >> >> W dniu wtorek, 18 września 2018 20:58:26 UTC+2 użytkownik nelson fernando >> garcia gomez napisał: >>> >>> Hola estoy tratando en mi formulario (formsModel) implementar el >>> atributo de *readonly* a una foreignkey (ModelChoiceField) >>> pero no es posible alguna ayuda por favor GRACIAS así lo estoy haciendo: >>> class CostoForm(forms.ModelForm): >>> >>> """ >>> Edicion de Costos con formset. >>> """ >>> class Meta: >>> model = Costo >>> exclude = ('user', ) >>> >>> def __init__(self, *args, **kwargs): >>> super(CostoForm, self).__init__(*args, **kwargs) >>> self.helper = FormHelper() >>> self.helper.form_tag = False >>> self.helper.form_action = '' >>> self.helper.form_class = 'form-inline' >>> self.helper.template = 'crispy_template/table_inline_formset.html' >>> self.helper.layout = Layout( >>> Field('DELETE', css_class='btn btn-primary') >>> ) >>> self.helper.add_input(Submit('submit', _('Aceptar'))) >>> self.fields['destination'].widget.attrs['readonly'] = True >>> >>> >>> >>> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/018da3ca-94eb-4c85-9a0b-af60dd1693b8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.