fix(access): field organization requires team related_model for org

ref: #526
This commit is contained in:
2025-02-07 21:23:14 +09:30
parent 4dd4215fd0
commit e8ce851c31
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,20 @@
# Generated by Django 5.1.5 on 2025-02-07 11:52
import access.models
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('access', '0005_teamnotes'),
]
operations = [
migrations.AlterField(
model_name='team',
name='organization',
field=models.ForeignKey(help_text='Organization this belongs to', on_delete=django.db.models.deletion.CASCADE, to='access.organization', validators=[access.models.Team.validatate_organization_exists], verbose_name='Organization'),
),
]

View File

@ -362,6 +362,18 @@ class Team(Group, TenancyObject):
super().save(force_insert=force_insert, force_update=force_update, using=using, update_fields=update_fields)
def validatate_organization_exists(self):
"""Ensure that the user did provide an organization
Raises:
ValidationError: User failed to supply organization.
"""
if not self:
raise ValidationError('You must provide an organization')
team_name = models.CharField(
blank = False,
help_text = 'Name to give this team',
@ -370,6 +382,16 @@ class Team(Group, TenancyObject):
verbose_name = 'Name',
)
organization = models.ForeignKey(
Organization,
blank = False,
help_text = 'Organization this belongs to',
null = False,
on_delete = models.CASCADE,
validators = [validatate_organization_exists],
verbose_name = 'Organization'
)
created = AutoCreatedField()
modified = AutoLastModifiedField()