X
X
xozzslip2015-07-07 02:41:07
Django
xozzslip, 2015-07-07 02:41:07

django authentication. How to make content differentiation between users?

How to implement the possibility of registration so that the user has access to only the database objects created by him? (How in Evernote you can only access your notes) And how to do it in such a way that objects with unique fields do not conflict if they belong to different users? (So ​​that urls like \user\app\SlugField(SlugField - see the deck name below ) are available, where a unique SlugField can be repeated for different users.)
The only thing that comes to mind is creating your own database for each user.
UPD: I am making an application with Anki functionality(program for memorization through repetition). Already implemented the decks, the cards themselves, adding cards, the process of repetition (implemented differently, actually because of this the idea appeared). But suddenly I discovered that in my application, anyone can add a card and anyone can read it. That is, everything falls into a heap, without determining the owner.
I want the user to be able to register and create their own instances of classes, to which he will have access. This, apparently, is done by creating a new model User, and add a field to the decksowner = models.ForeignKey(User). But the url to each deck I have is its name. Naturally, the url must be unique, which means the deck name must also be unique, but I want the same named decks of two different users not to conflict, but at the same time the same user could not name his two decks the same. Purpose: to organize urls in the way indicated above.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xozzslip, 2015-07-15
@xozzslip

You need to import the User class in models.py
And then add a relationship

class Deck(models.Model):
  #other fields
  slug = models.SlugField(max_length=30, blank=True, unique=False)
  owner = models.ForeignKey(User)
  class Meta:
    unique_together = (("owner", "slug"),)

S
sim3x, 2015-07-07
@sim3x

UserNote
   user = FK(MyUser)
   slug = SlugField(unique=False)

and then in the view you already give the user what she wrote or 404

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question