add multiselect for roles in services
This commit is contained in:
parent
88675bc807
commit
acad550dd0
|
@ -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']
|
||||
|
|
|
@ -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"),
|
||||
),
|
||||
]
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
</td>
|
||||
<td>
|
||||
{% for r in user.roles.all %}
|
||||
{{ r.service.rol.name }}
|
||||
{{ r.service.get_roles }}
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td><a type="button" class="btn btn-green-admin rounded-pill" href="{% url 'idhub:admin_people' user.id %}">{% trans 'View' %}</td>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<tr>
|
||||
<td>{{ service.domain }}</td>
|
||||
<td>{{ service.description }}</td>
|
||||
<td>{{ service.rol.name }}</td>
|
||||
<td>{{ service.get_roles }}</td>
|
||||
<td><a href="{% url 'idhub:admin_service_edit' service.id %}" title="{% trans 'Edit' %}"><i class="bi bi-pencil-square"></i></a></td>
|
||||
<td><a href="{% url 'idhub:admin_service_del' service.id %}" title="{% trans 'Delete' %}"><i class="bi bi-trash"></i></a></td>
|
||||
</tr>
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
<tbody>
|
||||
{% for rol in object.roles.all %}
|
||||
<tr>
|
||||
<td>{{ rol.service.rol.name }}</td>
|
||||
<td>{{ rol.service.get_roles }}</td>
|
||||
<td>{{ rol.service.description }}</td>
|
||||
<td>{{ rol.service.domain }}</td>
|
||||
</tr>
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
<tbody>
|
||||
{% for rol in object.roles.all %}
|
||||
<tr>
|
||||
<td>{{ rol.service.rol.name }}</td>
|
||||
<td>{{ rol.service.get_roles }}</td>
|
||||
<td>{{ rol.service.description }}</td>
|
||||
<td>{{ rol.service.domain }}</td>
|
||||
<td><a href="{% url 'idhub:admin_people_rol_edit' rol.id %}" title="{% trans 'Edit' %}"><i class="bi bi-pencil-square"></i></a></td>
|
||||
|
|
Loading…
Reference in New Issue