Skip to content Skip to sidebar Skip to footer

How To Handle Users And Roles By App In Django

Hello everyone let me ask something about the admin interface and how can I handle my users by app. Well so sorry I'm nooby first of all. So, I need to create a new app for basica

Solution 1:

From Django's documentation about Django admin - Link

model-centric interface where trusted users can manage content on your site.

Django comes with a user model, you can extend it to represent teachers and students as described in django's documentation here, you would create ModelAdmins and register your models. Beyond that you can manage your users easily through the admin system, example code:

models.py

from django.contrib.auth.models import Userfrom django.db import models


class Teacher(models.Model):
    user= models.ForeignKey(User, related_name='teacher')


class Student(models.Model):
    user= models.ForeignKey(User, related_name='student')

admin.py

from django.contribimport admin

from .modelsimportTeacher, Student


admin.site.register(Teacher)
admin.site.register(Student)

As for security, it is not clear what you mean by "use it as a security layer in my app", if you elaborate more, people can better help you. You can generally learn about security in django here.

Post a Comment for "How To Handle Users And Roles By App In Django"