Answer the question
In order to leave comments, you need to log in
DJANGO How to implement a user's personal account so that he can add data that will be linked (or available) only to him?
I have a specific project (just starting to learn django and how site building works in general). The essence of the project is a regular site for notes or user entries. The essence of the question is that I need to understand: how to make it so that a logged in user (already implemented) can create records that will be visible only to him. I believe that this needs to be implemented through model links, but I would like to know how to do this in detail?
models(model responsible for note data)
from django.db import models
from django.urls import reverse
from django.contrib.auth.models import User
class Note(models.Model):
title = models.CharField(max_length=150, verbose_name='Title')
content = models.TextField(verbose_name='Content')
created = models.DateTimeField(auto_now_add=True, verbose_name='Created')
photo = models.ImageField(verbose_name='Image', blank=True, upload_to='photo/%Y/%m/%d')
username = models .ForeignKey(User, verbose_name='User', null=True, on_delete=models.PROTECT)
Answer the question
In order to leave comments, you need to log in
so I believe that this needs to be implemented through model links,
username = models.ForeignKey(User, verbose_name='Пользователь', null=True, on_delete=models.PROTECT)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question