I’m thinking on this for a while. I have at least two Actors/Roles. “Student” and “Tutors”.
What I’ve done until now, was to make a choice field like this:
class UserProfile(UserenaBaseProfile):
Roles = [('Student' , 'Student') , ('Tutor' , 'Tutor')]
..
role = models.CharField(max_length = 20 , choices = actor_type , blank = True , null = True)
Now I got stuck to how to divide them in the views !!
There is a way to use user_passes_test on top a view, but I don’t know how to make groups as well ?!
If I only had a student, I could do something like this:
class Student(UserProfile):
"""
The Student actor and its necessary fields
"""
courses = models.ManyToManyField('courses.Course' , null = True, blank = True, related_name = _('student') , through = 'Registration')
class Meta:
verbose_name = _("Student")
verbose_name_plural = _("Students")
def save(self , *args , **kwargs):
super(Student , self).save(*args , **kwargs)
user, created = User.objects.get_or_create(username=self.username)
group , created = Group.objects.get_or_create(name = "Student")
if created: group.save()
user.groups.add(group)
user.save()
Would you please show me a detailed answer on how to do this:
UPDATE
If you want to work with an actual
Studentclass that automatically filters to just users in the “Student” group and automatically saves users to that group, use a proxy model, and subclassUser, notUserProfile: