Proper way to manage a list of form in Django

What is the best way to handle an array of forms in django? I am trying to create a custom permissions system and I have to do the form to create a role. The models involved are listed below:

class CategoryPermissions(models.Model):
    upload = models.BooleanField(default=False)
    download = models.BooleanField(default=False)
    history = models.BooleanField(default=False)

class Category(models.Model):
    name = models.CharField(max_length=250, unique=True)
    label = models.CharField(max_length=250)
    directory = models.CharField(max_length=250)

class GroupPermissions(models.Model):
    role = models.ForeignKey('repository.Role',on_delete=models.RESTRICT)
    category = models.ForeignKey('repository.Category',on_delete=models.RESTRICT)
    category_permissions = models.OneToOneField("repository.CategoryPermissions",on_delete=models.RESTRICT)

class Role(models.Model):
    name = models.CharField(max_length=250)

For each Category (which are already created) I define a CategoryPermissions that contains the permissions and I link it to the Role with GroupPermissions. How do I create a multiple form that allows me to create GroupPermissions with related CategoryPermissions, maintaining the relationship between GroupPermissions, Category and Role? I tried with a CategoryPermissions formset, but when I extract it from request.POST I don't know which one I understand that it may be unclear so do not hesitate to ask for more explanations, I will try to do my best.

Back to Top