i have custom user model as follows
class User(AbstractUser):
# if you need any other information regarding any type of these following kinds of users make a model for them
USER_TYPE_CHOICES = (
(1, 'admin'),
(2, 'supervisor'),
(3, 'instructor'),
(4, 'student'),
(5, 'customer'),
(6, 'employee'),
(7, 'advertiser'),
)
email = models.EmailField(verbose_name='email address', max_length=255, unique=True,)
is_active = models.BooleanField(default=True)
is_superuser = models.BooleanField(default=False) #is_admin = models.BooleanField(default=False)
objects = newUserManager()
USERNAME_FIELD = 'email' # string describing the name of the field on
REQUIRED_FIELDS = ["username"] # list of the field names that will be prompted
user_type = models.PositiveSmallIntegerField(choices=USER_TYPE_CHOICES, null=True, blank=True)
class Meta:
permissions = [
("change_post_status", "Can change the status of posts"),
("close_discussions", "Can remove a post by setting its status as closed"),
('can_publish', 'Can Publish Posts'),
]
and post model
class Post(models.Model):
id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True, primary_key=True)
title = models.CharField(max_length=200, db_index=True, blank=False, default='')
maintainer = models.ForeignKey(Maintainer, on_delete=models.SET_NULL, blank=True, null=True, related_name='post_maintainers')
creator = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="post_creator")
...
and post maintainer model
class Maintainer(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True, related_name='maintainers')
class Meta:
ordering = ['last_name', 'first_name']
def get_absolute_url(self):
return reverse('maintainer-detail', args=[str(self.id)])
def __str__(self) -> str:
return '{0}, {1}'.format(self.last_name, self.first_name)
and a model represent ManyTomany relation between users and posts
class PostInstance(models.Model): # Represenrt a Many To Many relation btn both post and users
id = models.UUIDField(primary_key=True, default=uuid.uuid4, unique=True, help_text="Unique ID for this particular post across whole blog")
post = models.ForeignKey(Post, on_delete=models.RESTRICT, null=True)
commenter = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True, related_name="commenter")
class Meta:
permissions = (("can_renew", "Set post new date"), ("can_edit", "Edit post details"))
the problem is when i try to go to create maintainer view
class MaintainerCreate(PermissionRequiredMixin, CreateView):
permission_required = ['blog.can_renew', 'account.can_publish']
model = Maintainer
fields = ['first_name', 'last_name',]
i got this error
ImproperlyConfigured at /blog/maintainer/create/
MaintainerCreate is missing the permission_required attribute. Define MaintainerCreate.permission_required, or override MaintainerCreate.get_permission_required().
the problem is that i don’t have any groups in user admin pages to assign the user to it
although i already put the following line in admin.py
filter_horizontal = ('groups', 'user_permissions',)
do i have to do custom migration methods
or do i have to override these methods
def get_permission_required(self):
perms = super(MaintainerCreate, self).get_permission_required()
return perms
def has_permission(self):
perms = super(MaintainerCreate, self).has_permission()
return perms
def get(self, request, *args, **kwargs):
return HttpResponse("Create Blog Maintainer")
or what to do to show the groups in users admin page
i don’t know a straightforwoard method really confused
some help please brother @KenWhitesell