Browse Source

Assign label colors automatically

pull/1564/head
Hironsan 3 years ago
parent
commit
39351d3f69
2 changed files with 25 additions and 1 deletions
  1. 19
      backend/api/migrations/0018_alter_label_background_color.py
  2. 7
      backend/api/models.py

19
backend/api/migrations/0018_alter_label_background_color.py

@ -0,0 +1,19 @@
# Generated by Django 3.2.8 on 2021-11-17 05:56
import api.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0017_example_uuid'),
]
operations = [
migrations.AlterField(
model_name='label',
name='background_color',
field=models.CharField(default=api.models.generate_random_hex_color, max_length=7),
),
]

7
backend/api/models.py

@ -1,3 +1,4 @@
import random
import string
import uuid
from typing import Literal
@ -94,6 +95,10 @@ class ImageClassificationProject(Project):
return task == 'image'
def generate_random_hex_color():
return f'#{random.randint(0, 0xFFFFFF):06x}'
class Label(models.Model):
text = models.CharField(max_length=100, db_index=True)
prefix_key = models.CharField(
@ -119,7 +124,7 @@ class Label(models.Model):
on_delete=models.CASCADE,
related_name='labels'
)
background_color = models.CharField(max_length=7, default='#209cee')
background_color = models.CharField(max_length=7, default=generate_random_hex_color)
text_color = models.CharField(max_length=7, default='#ffffff')
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True)

Loading…
Cancel
Save