mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 04:51:51 +00:00
PRWLR-3997: fix(Models): create BaseModel & TenantModel (#13)
* fix(Models): create BaseModel & TenantModel * update description to match class Co-authored-by: Víctor Fernández Poyatos <victor@prowler.com> * fix(Tenants): rename TenantModel to Tenant --------- Co-authored-by: Víctor Fernández Poyatos <victor@prowler.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
# Generated by Django 5.0.7 on 2024-07-12 16:45
|
||||
|
||||
import uuid
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("api", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Tenant",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.UUIDField(
|
||||
default=uuid.uuid4,
|
||||
editable=False,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
),
|
||||
),
|
||||
("inserted_at", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
("name", models.CharField(max_length=100)),
|
||||
],
|
||||
options={
|
||||
"abstract": False,
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -1,4 +1,27 @@
|
||||
from django.db import models
|
||||
import uuid
|
||||
|
||||
|
||||
class Base(models.Model):
|
||||
"""
|
||||
Abstract base model class that provides common fields for all models.
|
||||
"""
|
||||
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
|
||||
inserted_at = models.DateTimeField(auto_now_add=True, editable=False)
|
||||
updated_at = models.DateTimeField(auto_now=True, editable=False)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class Tenant(Base):
|
||||
"""
|
||||
The Tenant is the basic grouping in the system. It is used to separate data between customers.
|
||||
"""
|
||||
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
|
||||
class TestModel(models.Model):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from api.models import TestModel
|
||||
from api.models import TestModel, Tenant
|
||||
|
||||
|
||||
class TestModelSerializer(serializers.ModelSerializer):
|
||||
@@ -12,3 +12,13 @@ class TestModelSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = TestModel
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class TenantSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
Serializer for the Tenant model.
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Tenant
|
||||
fields = "__all__"
|
||||
|
||||
Reference in New Issue
Block a user