diff --git a/api/migrations/0027_remove_userprofile_first_name_and_more.py b/api/migrations/0027_remove_userprofile_first_name_and_more.py new file mode 100644 index 0000000..b58b94c --- /dev/null +++ b/api/migrations/0027_remove_userprofile_first_name_and_more.py @@ -0,0 +1,21 @@ +# Generated by Django 5.0.1 on 2024-04-04 08:50 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0026_alter_uploadtask_status'), + ] + + operations = [ + migrations.RemoveField( + model_name='userprofile', + name='first_name', + ), + migrations.RemoveField( + model_name='userprofile', + name='last_name', + ), + ] diff --git a/api/models.py b/api/models.py index b863fc0..c92ba28 100644 --- a/api/models.py +++ b/api/models.py @@ -24,8 +24,6 @@ def __str__(self): class UserProfile(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) user = models.OneToOneField(User, on_delete=models.CASCADE) - first_name = models.CharField(max_length=50, null=True, blank=True) - last_name = models.CharField(max_length=50, null=True, blank=True) organisation = models.ForeignKey( Organisation, on_delete=models.CASCADE, null=True, blank=True ) diff --git a/gmn/migrations/0016_gmn_color.py b/gmn/migrations/0016_gmn_color.py new file mode 100644 index 0000000..79029db --- /dev/null +++ b/gmn/migrations/0016_gmn_color.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.1 on 2024-04-04 07:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("gmn", "0015_alter_gmn_delivery_accountable_party_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="gmn", + name="color", + field=models.CharField(blank=True, max_length=7, null=True), + ), + ] diff --git a/gmn/migrations/0017_alter_gmn_color.py b/gmn/migrations/0017_alter_gmn_color.py new file mode 100644 index 0000000..ece1499 --- /dev/null +++ b/gmn/migrations/0017_alter_gmn_color.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.1 on 2024-04-04 08:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('gmn', '0016_gmn_color'), + ] + + operations = [ + migrations.AlterField( + model_name='gmn', + name='color', + field=models.CharField(blank=True, default=None, max_length=7, null=True), + ), + ] diff --git a/gmn/models.py b/gmn/models.py index 8a4f015..44c48db 100644 --- a/gmn/models.py +++ b/gmn/models.py @@ -1,3 +1,4 @@ +import random import uuid from django.db import models @@ -5,6 +6,11 @@ from api.models import Organisation +def generate_random_color(): + """Generate a random hex color code.""" + return f"#{random.randint(0, 0xFFFFFF):06x}" + + class GMN(models.Model): """Groundwater Monitoring Network @@ -25,10 +31,16 @@ class GMN(models.Model): start_date_monitoring = models.DateField(null=True) object_registration_time = models.DateTimeField(null=True) registration_status = models.CharField(max_length=50, null=True) + color = models.CharField(max_length=7, null=True, blank=True, default=None) def __str__(self): return self.bro_id + def save(self, *args, **kwargs): + if not self.color: + self.color = generate_random_color() + super().save(*args, **kwargs) + class Meta: verbose_name_plural = "GMN's"