mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Enable many-to-many model assignment for ObjectPermissions
This commit is contained in:
@@ -89,8 +89,8 @@ class ObjectPermissionForm(forms.ModelForm):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Format ContentType choices
|
||||
order_content_types(self.fields['model'])
|
||||
self.fields['model'].choices.insert(0, ('', '---------'))
|
||||
order_content_types(self.fields['content_types'])
|
||||
self.fields['content_types'].choices.insert(0, ('', '---------'))
|
||||
|
||||
|
||||
@admin.register(ObjectPermission)
|
||||
|
@@ -1,9 +1,8 @@
|
||||
# Generated by Django 3.0.6 on 2020-05-27 14:17
|
||||
# Generated by Django 3.0.6 on 2020-05-28 18:24
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.postgres.fields.jsonb
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@@ -25,12 +24,9 @@ class Migration(migrations.Migration):
|
||||
('can_add', models.BooleanField(default=False)),
|
||||
('can_change', models.BooleanField(default=False)),
|
||||
('can_delete', models.BooleanField(default=False)),
|
||||
('content_types', models.ManyToManyField(limit_choices_to={'app_label__in': ['circuits', 'dcim', 'extras', 'ipam', 'secrets', 'tenancy', 'virtualization']}, related_name='object_permissions', to='contenttypes.ContentType')),
|
||||
('groups', models.ManyToManyField(blank=True, related_name='object_permissions', to='auth.Group')),
|
||||
('model', models.ForeignKey(limit_choices_to={'app_label__in': ['circuits', 'dcim', 'extras', 'ipam', 'secrets', 'tenancy', 'virtualization']}, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
|
||||
('users', models.ManyToManyField(blank=True, related_name='object_permissions', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'unique_together': {('model', 'attrs')},
|
||||
},
|
||||
),
|
||||
]
|
||||
|
@@ -212,14 +212,14 @@ class ObjectPermission(models.Model):
|
||||
blank=True,
|
||||
related_name='object_permissions'
|
||||
)
|
||||
model = models.ForeignKey(
|
||||
content_types = models.ManyToManyField(
|
||||
to=ContentType,
|
||||
limit_choices_to={
|
||||
'app_label__in': [
|
||||
'circuits', 'dcim', 'extras', 'ipam', 'secrets', 'tenancy', 'virtualization',
|
||||
],
|
||||
},
|
||||
on_delete=models.CASCADE
|
||||
related_name='object_permissions'
|
||||
)
|
||||
attrs = JSONField(
|
||||
blank=True,
|
||||
@@ -239,8 +239,8 @@ class ObjectPermission(models.Model):
|
||||
default=False
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('model', 'attrs')
|
||||
def __str__(self):
|
||||
return "Object permission"
|
||||
|
||||
def clean(self):
|
||||
|
||||
|
Reference in New Issue
Block a user