Override value of a TextField class method.

35 views
Skip to first unread message

Fabio da Silva Pedro

unread,
Jan 6, 2020, 3:37:05 PM1/6/20
to Django users
Hi everyone!

this is an excerpt line from my model

observacoes = models.TextField(null=True, blank=True, verbose_name='Informações complementares')

How i do override a field type TextField and change your internal class value Textarea, this is a widget from TextField Class and override this method below:

def __init__(self, attrs=None):
# Use slightly better defaults than HTML's 20x2 box
default_attrs = {'cols': '40', 'rows': '10'}
if attrs:
default_attrs.update(attrs)
super().__init__(default_attrs)

I need change value from default_attrs = {'rows':'10'} for {'rows':'4'} 

 How can I override this in my model or in my view?

Thanks for watching!

Mohamed A

unread,
Jan 6, 2020, 4:37:35 PM1/6/20
to django...@googlegroups.com
Easy. You need to provide attrs as dict to the new object. 

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/adef9112-df5b-4b03-9861-97d1495dd00b%40googlegroups.com.

Fabio da Silva Pedro

unread,
Jan 6, 2020, 5:03:13 PM1/6/20
to django...@googlegroups.com
Easy. You need to provide attrs as dict to the new object. 


Ok, I thought about that too, but I don't know how to do it, I copied the whole method and pasted it into my model and tried to access its superclass, but I didn't get it!
Maybe I'm doing something wrong yet.

Would you have any examples for me?

I can easily do this with jQuery, but I want to learn how to do this using just Django and for that I still have little experience in method override.

best regards! 

Mohamed A

unread,
Jan 7, 2020, 1:03:30 AM1/7/20
to django...@googlegroups.com
Hint:.. __init__ is a constructor not any method. 

--
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...@googlegroups.com.

Fabio da Silva Pedro

unread,
Jan 7, 2020, 9:06:55 AM1/7/20
to django...@googlegroups.com
OK, thank's for this!



--
Fábio S. Pedro 
(21) 97569-7573(WhatsApp).
Reply all
Reply to author
Forward
0 new messages