Skip to content

Commit

Permalink
Inherit from BaseModel to get correct created_at/updated_at.
Browse files Browse the repository at this point in the history
  • Loading branch information
terjekv committed Dec 6, 2024
1 parent c66c7a6 commit 6c4b342
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by Django 5.0.9 on 2024-11-28 11:39
# Generated by Django 5.0.9 on 2024-12-02 12:17

import datetime
import django.db.models.deletion
import mreg.fields
import mreg.models.policy
Expand All @@ -19,8 +18,8 @@ class Migration(migrations.Migration):
name='PolicyAtom',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('create_date', models.DateField(default=datetime.date.today)),
('description', models.CharField(max_length=150)),
('name', mreg.fields.LowerCaseCharField(max_length=64, unique=True, validators=[mreg.models.policy._validate_atom_name])),
],
Expand All @@ -33,6 +32,8 @@ class Migration(migrations.Migration):
name='ApprovedModelForPolicy',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
],
options={
Expand All @@ -43,8 +44,8 @@ class Migration(migrations.Migration):
name='PolicyRole',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('create_date', models.DateField(default=datetime.date.today)),
('description', models.CharField(max_length=150)),
('name', mreg.fields.LowerCaseCharField(max_length=64, unique=True, validators=[mreg.models.policy._validate_role_name])),
('atoms', models.ManyToManyField(related_name='roles', to='mreg.policyatom')),
Expand All @@ -59,6 +60,8 @@ class Migration(migrations.Migration):
name='PolicyAssignment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('object_id', models.PositiveIntegerField()),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
('policy_role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='assignments', to='mreg.policyrole')),
Expand Down
11 changes: 5 additions & 6 deletions mreg/models/policy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime

from abc import abstractmethod

Expand All @@ -7,24 +6,24 @@
from django.core.exceptions import ValidationError
from django.db import models


from structlog import get_logger

from mreg.models.base import BaseModel
from mreg.fields import LowerCaseCharField
from mreg.managers import LowerCaseManager
from mreg.models.base import Label

logger = get_logger()


class PolicyComponent(models.Model):
class PolicyComponent(BaseModel):
"""Abstract base class for policy components.
This class provides common fields and methods for policy-related models.
Subclasses are expected to define a 'name' field.
"""

updated_at = models.DateTimeField(auto_now=True)
create_date = models.DateField(default=datetime.date.today)
description = models.CharField(max_length=150)

class Meta:
Expand Down Expand Up @@ -93,7 +92,7 @@ class Meta:
ordering = ("name",)


class ApprovedModelForPolicy(models.Model):
class ApprovedModelForPolicy(BaseModel):
"""
Model representing an approved model for policy assignments.
Expand All @@ -112,7 +111,7 @@ class Meta:
db_table = "approved_model_for_policy"


class PolicyAssignment(models.Model):
class PolicyAssignment(BaseModel):
"""
Model representing the assignment of a policy role to an object.
Expand Down

0 comments on commit 6c4b342

Please # to comment.