sinθ
sinθ

Reputation: 11503

Storing User Information Django

For Users on a website, what is the best way to store information in Django with databases. The website I'm working on has the following sections:

  1. A sort of chat room where users can post comments.
  2. A set of documents that are public to other users.
  3. Reviews for each document

The question is, where should the documents be stored? (I don't know how many each person will have). For each doc, where should the reviews be stored? (I don't know how many reviews there will be).

I'm very new to Django and have only just started the book I bought, but need to begin planning in order to get it done by august (Is that even possible for someone so new?).

Upvotes: 2

Views: 371

Answers (2)

Paulo Scardine
Paulo Scardine

Reputation: 77389

Straight forward OOP, you should just create a Model (object) for each artifact - for example:

class ChatComment(models.Model):
    owner = models.ForeignKey(User)
    when = models.DateTimeField(auto_now_add=True)
    message = models.CharField(...)
    ...
    chatroom = models.ForeignKey(ChatRoom)

class PublicDocument(models.Model):
    owner = models.ForeignKey(User)
    created = models.DateTimeField(auto_now_add=True)
    title = models.CharField(...)
    payload = models.FileField(...)

class DocumentReview(models.Model):
    author = models.ForeignKey(User)
    document = models.ForeignKey(PublicDocument)
    when = models.DateTimeField(auto_now_add=True)
    text = models.CharField(...)

And so on...

Upvotes: 5

aychedee
aychedee

Reputation: 25629

Paulo's answer is spot on. But I would also add that you should read the documentation for the FileField carefully.

The documents would generally be stored in a directory on the filesystem. The database (as per Paulo's answer) would contain a reference to the location. Django can do this for you almost automatically using the FileField so just read through that and make sure you understand it.

Upvotes: 1

Related Questions