Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Why not create a table per user?</strong> Creating a db table per user is definitely not recommended. How would you create a table for every user? Raw SQL statements? As far as I know, you would break the main purpose of Django, it's ORM (object relational mapper) -- it's easy interface to SQL because it doesn't support automatically creating tables per user / knowing how to query it.</p> <p>Definitely, definitely use a table with a <code>ForeignKey</code> to the <code>User</code> table. Every table has a Primary Key field which is generally a number. One table can refer to another table via that Primary Key.</p> <p>For example <code>Entry 1 belongs to User ID 3</code>.</p> <p>Luckily, django abstracts the SQL layer and this is done via the <code>ForeignKey</code> field. </p> <p><a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey</a></p> <hr> <p>As you are the one constructing queries for the database, only showing entries written by a specific user is a non-issue. You would simply only query the database for entries by the logged in user. As long as there are no loopholes for raw SQL to be input from outside your program, there's no way a user can access others data. </p> <hr> <p>To learn about best practice / ForeignKey's / querying etc, I suggest following the tutorial online. I think the documentation and tutorials are one of django's greatest assets. </p> <p><a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/" rel="nofollow">http://docs.djangoproject.com/en/dev/intro/tutorial01/</a> </p> <p>In the first tutorial they cover creating a <code>Poll</code> app, which includes a <code>Choices</code> model with a <code>ForeignKey</code> to <code>Poll</code> </p> <p>You can definitely apply this back to your model : )</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload