diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py index 74046df..fc66f14 100644 --- a/idhub/admin/forms.py +++ b/idhub/admin/forms.py @@ -1,5 +1,6 @@ from django import forms from django.contrib.auth.models import User +from idhub.models import Rol class ProfileForm(forms.ModelForm): @@ -21,5 +22,6 @@ class RolForm(forms.ModelForm): class ServiceForm(forms.ModelForm): MANDATORY_FIELDS = ['domain', 'rol'] + class UserRolForm(forms.ModelForm): MANDATORY_FIELDS = ['service'] diff --git a/idhub/migrations/0005_remove_service_rol_service_rol.py b/idhub/migrations/0005_remove_service_rol_service_rol.py new file mode 100644 index 0000000..a383ca4 --- /dev/null +++ b/idhub/migrations/0005_remove_service_rol_service_rol.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.5 on 2023-10-19 13:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("idhub", "0004_userrol"), + ] + + operations = [ + migrations.RemoveField( + model_name="service", + name="rol", + ), + migrations.AddField( + model_name="service", + name="rol", + field=models.ManyToManyField(to="idhub.rol"), + ), + ] diff --git a/idhub/models.py b/idhub/models.py index 6c143b7..3c187b3 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -92,12 +92,13 @@ class Rol(models.Model): class Service(models.Model): domain = models.CharField(max_length=250) description = models.CharField(max_length=250) - rol = models.ForeignKey( + rol = models.ManyToManyField( Rol, - on_delete=models.CASCADE, - related_name='services', ) + def get_roles(self): + return ", ".join([x.name for x in self.rol.all()]) + def __str__(self): return "{} -> {}".format(self.domain, self.rol.name) diff --git a/idhub/templates/idhub/admin/people.html b/idhub/templates/idhub/admin/people.html index 69cd758..ff19975 100644 --- a/idhub/templates/idhub/admin/people.html +++ b/idhub/templates/idhub/admin/people.html @@ -31,7 +31,7 @@