Cupitor
Cupitor

Reputation: 11657

When a property of a model is a huge text

If a model in an application has a very large(in size) text property and even longtext would not be able to contain it, one possible way to store it seems to store it in a text file and use the text location as field of the database. However I am not sure with such a strategy what would be proper for naming this property?

For example suppose we have:

class Novel(models.Model):
    ???? = models.CharField(max_length=200)

Should I name this property novel_text or novel_text_path? And is this a proper way of storing huge texts?

I hope this doesn't seem as a silly question.

Thanks.

Upvotes: 0

Views: 2199

Answers (3)

Károly Nagy
Károly Nagy

Reputation: 1754

If you want to store this text in a separate file I would recommend to name it novel_text_file or something similar to make it as clear and logical as possible and as Pratik wrote I would use Django's filefield.

But I don't think this is the best solution for storing data like this. Imagine if you need to scale up your system. Storing data in files make it significantly harder. You have to sync files to all server or share them.

One possible solution is using MongoDB's GridFS. This might be useful: http://django-mongodb.org/topics/gridfs.html

Upvotes: 2

Pratik Mandrekar
Pratik Mandrekar

Reputation: 9566

You should name it similar to file_path since that is what it is. Also use Django Model FileField

Upvotes: 0

pemistahl
pemistahl

Reputation: 9584

Have you tried Django's TextField ? It has been made for cases in which you have to store long texts.

Upvotes: 4

Related Questions