Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appropriateness of a Django Textfield in a Model

I have a field in a model that I want users to feel like they can write an arbitrary amount of text in. Django provides a CharField and a TextField in the models. I assume that the difference is that one of them is a char(max_length) and the other is a varchar internally.

I am tempted to use the TextField, but since it doesn't respect max_length, I am somewhat wary of someone dumping loads of data into it and DOSing my server. How should I deal with this?

Thanks!

like image 667
SapphireSun Avatar asked Jan 10 '10 10:01

SapphireSun


1 Answers

Fields in model only represent the way data is stored in database.

You can very easily enforce maximum length in form which will validate users' input. Like this.

class InputForm(forms.Form):
    text = forms.CharField(max_length=16384, widget=forms.TextArea)
    ...

This will make sure the maximum length user can successfully enter is 16k.

like image 50
af. Avatar answered Sep 21 '22 09:09

af.