mirror of
				https://github.com/netbox-community/netbox.git
				synced 2024-05-10 07:54:54 +00:00 
			
		
		
		
	CustomField.type to slug
This commit is contained in:
		@@ -8,8 +8,6 @@ import django.db.models.deletion
 | 
			
		||||
import extras.models
 | 
			
		||||
from django.db.utils import OperationalError
 | 
			
		||||
 | 
			
		||||
from extras.constants import CF_FILTER_DISABLED, CF_FILTER_EXACT, CF_FILTER_LOOSE, CF_TYPE_SELECT
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def verify_postgresql_version(apps, schema_editor):
 | 
			
		||||
    """
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
# Generated by Django 1.11.9 on 2018-02-21 19:48
 | 
			
		||||
from django.db import migrations, models
 | 
			
		||||
 | 
			
		||||
from extras.constants import CF_FILTER_DISABLED, CF_FILTER_EXACT, CF_FILTER_LOOSE, CF_TYPE_SELECT
 | 
			
		||||
from extras.constants import CF_FILTER_DISABLED, CF_FILTER_EXACT, CF_FILTER_LOOSE
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def is_filterable_to_filter_logic(apps, schema_editor):
 | 
			
		||||
@@ -10,7 +10,7 @@ def is_filterable_to_filter_logic(apps, schema_editor):
 | 
			
		||||
    CustomField.objects.filter(is_filterable=False).update(filter_logic=CF_FILTER_DISABLED)
 | 
			
		||||
    CustomField.objects.filter(is_filterable=True).update(filter_logic=CF_FILTER_LOOSE)
 | 
			
		||||
    # Select fields match on primary key only
 | 
			
		||||
    CustomField.objects.filter(is_filterable=True, type=CF_TYPE_SELECT).update(filter_logic=CF_FILTER_EXACT)
 | 
			
		||||
    CustomField.objects.filter(is_filterable=True, type=600).update(filter_logic=CF_FILTER_EXACT)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def filter_logic_to_is_filterable(apps, schema_editor):
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								netbox/extras/migrations/0029_3569_customfield_fields.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								netbox/extras/migrations/0029_3569_customfield_fields.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
from django.db import migrations, models
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CUSTOMFIELD_TYPE_CHOICES = (
 | 
			
		||||
    (100, 'text'),
 | 
			
		||||
    (200, 'integer'),
 | 
			
		||||
    (300, 'boolean'),
 | 
			
		||||
    (400, 'date'),
 | 
			
		||||
    (500, 'url'),
 | 
			
		||||
    (600, 'select')
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def customfield_type_to_slug(apps, schema_editor):
 | 
			
		||||
    CustomField = apps.get_model('extras', 'CustomField')
 | 
			
		||||
    for id, slug in CUSTOMFIELD_TYPE_CHOICES:
 | 
			
		||||
        CustomField.objects.filter(type=str(id)).update(type=slug)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Migration(migrations.Migration):
 | 
			
		||||
    atomic = False
 | 
			
		||||
 | 
			
		||||
    dependencies = [
 | 
			
		||||
        ('extras', '0028_remove_topology_maps'),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    operations = [
 | 
			
		||||
        migrations.AlterField(
 | 
			
		||||
            model_name='customfield',
 | 
			
		||||
            name='type',
 | 
			
		||||
            field=models.CharField(default='text', max_length=50),
 | 
			
		||||
        ),
 | 
			
		||||
        migrations.RunPython(
 | 
			
		||||
            code=customfield_type_to_slug
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
		Reference in New Issue
	
	Block a user