Commit d9ff14e6 by Szabolcs Gelencser

Save role name instead of it's id

parent d92716d6
...@@ -574,12 +574,12 @@ class LeaseForm(forms.ModelForm): ...@@ -574,12 +574,12 @@ class LeaseForm(forms.ModelForm):
if roles: if roles:
self.fields['roles'].choices = ( self.fields['roles'].choices = (
(role.id, role.name) for role in roles (role.name, role.name) for role in roles
) )
related_roles = self.instance.roles_permitted.all() related_roles = self.instance.roles_permitted.all()
self.fields['roles'].initial = [ self.fields['roles'].initial = [
role.role_id for role in related_roles role.role_name for role in related_roles
] ]
self.generate_fields() self.generate_fields()
...@@ -650,11 +650,11 @@ class LeaseForm(forms.ModelForm): ...@@ -650,11 +650,11 @@ class LeaseForm(forms.ModelForm):
self.instance.suspend_interval = suspend_seconds self.instance.suspend_interval = suspend_seconds
self.instance.roles_permitted.clear() self.instance.roles_permitted.clear()
for role_id in data['roles']: for role_name in data['roles']:
try: try:
self.instance.roles_permitted.add(Role.objects.get(role_id=role_id)) self.instance.roles_permitted.add(Role.objects.get(role_name=role_name))
except Role.DoesNotExist: except Role.DoesNotExist:
self.instance.roles_permitted.create(role_id=role_id) self.instance.roles_permitted.create(role_name=role_name)
instance = super(LeaseForm, self).save(commit=False) instance = super(LeaseForm, self).save(commit=False)
if commit: if commit:
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-05-22 13:15
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('vm', '0015_auto_20180522_1429'),
]
operations = [
migrations.RenameField(
model_name='role',
old_name='role_id',
new_name='role_name',
),
]
...@@ -65,7 +65,7 @@ class NamedBaseResourceConfig(BaseResourceConfigModel, TimeStampedModel): ...@@ -65,7 +65,7 @@ class NamedBaseResourceConfig(BaseResourceConfigModel, TimeStampedModel):
class Role(Model): class Role(Model):
role_id = CharField(blank=False, max_length=100, unique=True) role_name = CharField(blank=False, max_length=100, unique=True)
class Meta: class Meta:
app_label = 'vm' app_label = 'vm'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment