Thursday, January 26, 2017

Re: Multiple (limited) Admin feature for each registered user - Best Approach.

On Thursday 26 January 2017 12:10:07 Mike08 wrote:

 

> Now each teacher (Teacher model) is assigned a Subject (subject

> Model). Now each Teacher should have an admin section they should not

> be able to change their name, they should not be able to change their

> subject but they can create new topics that they would like to

> discuss in their class(Topic Model). My question is what would be the

> best approach to handle this.

>

> Example:

>

> *class Subject(models.Model):*

> * name = models.CharField(max_length=200)*

> * text = models.CharField(max_length=200)*

>

> *class Topic(models.Model)*

> * topic_name = models.CharField(max_length=200)*

>

> *class Teacher(models.Model):*

> * name = models.CharField(max_length=200)*

> * subject= models.ForeignKey('Subject')*

> * topic= models.ForeignKey('Subject')*

> * text = models.TextField()*

>

 

This is explained in the docs, but tucked away. Also review the contrib.auth part about Permissions and Authorization.

In short, by creating the proper groups and sticking the users in there, one can assign the basic CRUD permissions per object.

Finer-grained control can be achieved with custom permissions and the user_passes_test decorator.

--

Melvyn Sopacua

No comments:

Post a Comment