Django: individual user data

I am trying to train as / the best, safest way to save individual user data on a django site that I need to write.

Here is an example of what I need to do ...

ToDoList sample application

Using django contrib.auth to manage users / passwords, etc., I will have the following users.

Tom jim lee

There will be a ToDo model (additional models will appear in my real application)

class ToDo(models.Model):
    user = models.ForeignKey(User)
    description = models.CharField(max_length=20)
    details = models.CharField(max_length=50)
    created = models.DateTimeField('created on')

The problem I am facing - and maybe I’m thinking about it: how it will be blocked, so Tom can only see Tom Todo's list, Lee can only see his todo list, etc ...

, URL-, URL- www.domain.com/username/todo

, / , .

+5
2

- ToDo :

from django.contrib.auth.decorators import login_required
from django.shortcuts import render

from your_app.models import ToDo

@login_required
def todos_for_user(request):
    todos = ToDo.objects.filter(user=request.user)
    return render(request, 'todos/index.html', {'todos' : todos})

, , , ToDo. , .

+8

URL-, www.domain.com/username/todo, , .

, , , ,

  • , .
  • (ID ) Todo.

, .

, .

+1

All Articles