Skip to content

Commit

Permalink
Merge pull request #19 from nens/florian-aanpassingen
Browse files Browse the repository at this point in the history
Florian aanpassingen
  • Loading branch information
JJFlorian authored Apr 4, 2024
2 parents 57ee2c3 + 7eee4f1 commit 2f7e829
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
21 changes: 21 additions & 0 deletions api/migrations/0027_remove_userprofile_first_name_and_more.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
2 changes: 0 additions & 2 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
17 changes: 17 additions & 0 deletions gmn/migrations/0016_gmn_color.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
18 changes: 18 additions & 0 deletions gmn/migrations/0017_alter_gmn_color.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
12 changes: 12 additions & 0 deletions gmn/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import random
import uuid

from django.db import models

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
Expand All @@ -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"

Expand Down

0 comments on commit 2f7e829

Please sign in to comment.