Skip to content

Commit

Permalink
[fix] Fixed database model.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneyan committed Mar 31, 2024
1 parent fc9bfd5 commit 34e4640
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 5.0.3 on 2024-03-31 16:12

import dsbd.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ip', '0002_initial'),
]

operations = [
migrations.AlterField(
model_name='ip',
name='ip_address',
field=models.GenericIPAddressField(blank=True, null=True, unique=True, verbose_name='IP Address'),
),
migrations.AlterField(
model_name='ip',
name='use_case',
field=dsbd.models.MediumTextField(blank=True, default='', verbose_name='使用用途'),
),
migrations.AlterField(
model_name='jpnicuser',
name='fax',
field=models.CharField(blank=True, default='', max_length=30, verbose_name='fax'),
),
]
28 changes: 17 additions & 11 deletions ip/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@


class IP(models.Model):
class Meta:
ordering = ("id",)
verbose_name = "IP"
verbose_name_plural = "IPs"

created_at = models.DateTimeField("作成日", default=timezone.now)
updated_at = models.DateTimeField("更新日", default=timezone.now)
is_active = models.BooleanField("有効", default=True)
service = models.ForeignKey(Service, on_delete=models.SET_NULL, related_name="IPService", null=True, blank=True)
ip_address = models.GenericIPAddressField("IP Address", unique=True)
ip_address = models.GenericIPAddressField("IP Address", unique=True, null=True, blank=True)
subnet = models.IntegerField("サブネット", default=32)
start_at = models.DateTimeField("開通日", null=True, blank=True)
end_at = models.DateTimeField("解約日", null=True, blank=True)
plan = models.JSONField("プラン", null=True, blank=True)
use_case = MediumTextField("使用用途", default="")
use_case = MediumTextField("使用用途", default="", blank=True)
jpnic_user = models.ManyToManyField(
"JPNICUser",
blank=True,
Expand All @@ -45,10 +50,8 @@ class IP(models.Model):
related_name="jpnic_user_set",
)

class Meta:
ordering = ("id",)
verbose_name = "IP"
verbose_name_plural = "IPs"
def __str__(self):
return "%d: %s/%s" % (self.id, self.ip_address, self.subnet)


HANDLE_TYPE_GROUP = "group_handle"
Expand All @@ -61,6 +64,11 @@ class Meta:


class JPNICUser(models.Model):
class Meta:
ordering = ("id",)
verbose_name = "JPNIC User"
verbose_name_plural = "JPNIC Users"

created_at = models.DateTimeField("作成日", default=timezone.now)
updated_at = models.DateTimeField("更新日", default=timezone.now)
group = models.ForeignKey(Group, on_delete=models.CASCADE)
Expand All @@ -81,7 +89,7 @@ class JPNICUser(models.Model):
title = models.CharField("役職", max_length=250, default="", blank=True)
title_jp = models.CharField("役職(Japanese)", max_length=250, default="", blank=True)
tel = models.CharField("tel", max_length=30, default="")
fax = models.CharField("fax", max_length=30, default="")
fax = models.CharField("fax", max_length=30, default="", blank=True)
country = models.CharField("居住国", max_length=100, default="Japan")
ip = models.ManyToManyField(
"IP",
Expand All @@ -91,10 +99,8 @@ class JPNICUser(models.Model):
related_name="jpnic_set",
)

class Meta:
ordering = ("id",)
verbose_name = "JPNIC User"
verbose_name_plural = "JPNIC Users"
def __str__(self):
return "%d: %s(%s)" % (self.id, self.name, self.name_jp)


JPNIC_USER_TYPE_ADMIN = "admin"
Expand Down
3 changes: 3 additions & 0 deletions noc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ class Meta:
location = models.CharField("場所", default="", max_length=255, blank=True)
bandwidth = models.IntegerField("帯域幅", default=1000)
comment = MediumTextField("コメント", default="", blank=True)

def __str__(self):
return "%d: %s" % (self.id, self.name)
6 changes: 6 additions & 0 deletions router/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class Meta:
hostname = models.CharField("ホスト名", unique=True, max_length=255)
comment = MediumTextField("コメント", default="", blank=True)

def __str__(self):
return "%d: %s" % (self.id, self.hostname)


class TunnelIP(models.Model):
class Meta:
Expand All @@ -31,3 +34,6 @@ class Meta:
tunnel_router = models.ForeignKey(TunnelRouter, on_delete=models.CASCADE)
ip_address = models.GenericIPAddressField("IPアドレス", unique=True)
comment = MediumTextField("コメント", default="", blank=True)

def __str__(self):
return "%d: (%s)%s" % (self.id, self.tunnel_router.hostname,self.ip_address)
10 changes: 5 additions & 5 deletions service/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
@admin.register(Service)
class Service(admin.ModelAdmin):
fieldsets = (
(None, {'fields': ('is_active', 'is_pass', 'allow_connection_add')}),
(None, {'fields': ('is_active', 'is_pass', 'allow_connection_add', 'group')}),
('service', {'fields': ('service_type', 'service_number', 'start_at', 'end_at', 'asn')}),
('bandwidth',
{'fields': ('ave_upstream', 'max_upstream', 'ave_downstream', 'max_downstream', 'max_bandwidth_as')}),
('comment', {'fields': ('user_comment', 'admin_comment')}),
('Important dates', {'fields': ('created_at', 'updated_at',)}),
)
list_display = ('id', 'is_active', 'is_pass', 'group', 'start_at', 'end_at')
list_display = ('service_code', 'is_active', 'is_pass', 'group', 'start_at', 'end_at')
list_filter = ('end_at',)
search_fields = ('end_at', 'is_active', 'service_type')
search_fields = ('service_code', 'is_active', 'service_type')


@admin.register(Connection)
Expand All @@ -31,6 +31,6 @@ class Connection(admin.ModelAdmin):
('comment', {'fields': ('user_comment', 'admin_comment')}),
('Important dates', {'fields': ('created_at', 'updated_at',)}),
)
list_display = ('id', 'is_active', 'is_open', 'service', 'start_at', 'end_at')
list_display = ('service_code', 'is_active', 'is_open', 'service', 'start_at', 'end_at')
list_filter = ('is_active', 'is_open', 'start_at', 'end_at',)
search_fields = ('is_active', 'service_type')
search_fields = ('service_code', 'is_active', 'service_type')
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 5.0.3 on 2024-03-31 16:31

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('router', '0001_initial'),
('service', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='connection',
name='connection_comment',
field=models.CharField(blank=True, default='', max_length=255, verbose_name='接続情報コメント'),
),
migrations.AlterField(
model_name='connection',
name='connection_number',
field=models.IntegerField(default=1, verbose_name='接続番号'),
),
migrations.AlterField(
model_name='connection',
name='connection_type',
field=models.CharField(choices=[('EIP', 'EtherIP Tunnel'), ('GRE', 'GRE Tunnel'), ('IPT', 'IPT Tunnel'), ('CC0', 'Cross Connect'), ('ETC', 'ETC')], default='EIP', max_length=255, verbose_name='接続タイプ'),
),
migrations.AlterField(
model_name='connection',
name='ipv4_route',
field=models.CharField(choices=[('none', 'None'), ('full_route', 'Full Route'), ('default_route', 'Default Route'), ('full_route', 'Etc')], default='full_route', max_length=255, verbose_name='IPv4 Route'),
),
migrations.AlterField(
model_name='connection',
name='ipv6_route',
field=models.CharField(choices=[('none', 'None'), ('full_route', 'Full Route'), ('default_route', 'Default Route'), ('full_route', 'Etc')], default='full_route', max_length=255, verbose_name='IPv6 Route'),
),
migrations.AlterField(
model_name='connection',
name='tunnel_ip',
field=models.ForeignKey(blank=True, max_length=255, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ConnectionTunnelIP', to='router.tunnelip'),
),
migrations.AlterField(
model_name='service',
name='service_comment',
field=models.CharField(blank=True, default='', max_length=255, verbose_name='サービス情報コメント'),
),
migrations.AlterField(
model_name='service',
name='service_number',
field=models.IntegerField(default=1, verbose_name='サービス番号'),
),
migrations.AlterField(
model_name='service',
name='service_type',
field=models.CharField(choices=[('2000', 'L2'), ('3S00', 'L3 Static'), ('3B00', 'L3 BGP'), ('IP3B', 'トランジット提供'), ('CL20', 'コロケーションサービス(L2)'), ('CL3S', 'コロケーションサービス(L3 Static)'), ('CL3B', 'コロケーションサービス(L3 BGP)'), ('ET00', 'その他')], default='CL3B', max_length=255, verbose_name='サービスタイプ'),
),
]
30 changes: 23 additions & 7 deletions service/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class Meta:
created_at = models.DateTimeField("作成日", default=timezone.now)
updated_at = models.DateTimeField("更新日", default=timezone.now)
group = models.ForeignKey(Group, on_delete=models.SET_NULL, related_name="ServiceGroup", null=True, blank=True)
service_type = models.IntegerField("サービスタイプ", choices=SERVICE_CHOICES, default=SERVICE_COLO_L3_BGP)
service_number = models.IntegerField("サービス番号", default=0)
service_comment = models.IntegerField("サービス情報コメント", default=0, blank=True)
service_type = models.CharField("サービスタイプ", choices=SERVICE_CHOICES, default=SERVICE_COLO_L3_BGP, max_length=255)
service_number = models.IntegerField("サービス番号", default=1)
service_comment = models.CharField("サービス情報コメント", default="", blank=True, max_length=255)
is_active = models.BooleanField("有効", default=True)
is_pass = models.BooleanField("審査OK", default=False)
allow_connection_add = models.BooleanField("接続追加許可", default=True)
Expand All @@ -66,6 +66,10 @@ class Meta:

objects = ServiceManager()

@property
def service_code(self):
return "%s-%s%s" % (self.group.id, self.service_type, str(self.service_number).zfill(3),)

def __str__(self):
return "%s-%s%s" % (self.group.id, self.service_type, str(self.service_number).zfill(3),)

Expand Down Expand Up @@ -100,11 +104,13 @@ def __str__(self):
(NTT_TYPE6, "etc"),
)

ROUTE_NONE = "none"
ROUTE_FULL_ROUTE = "full_route"
ROUTE_DEFAULT_ROUTE = "default_route"
ROUTE_ETC = "full_route"

ROUTE_CHOICES = (
(ROUTE_NONE, "None"),
(ROUTE_FULL_ROUTE, "Full Route"),
(ROUTE_DEFAULT_ROUTE, "Default Route"),
(ROUTE_ETC, "Etc"),
Expand All @@ -129,12 +135,12 @@ class Meta:
created_at = models.DateTimeField("作成日", default=timezone.now)
updated_at = models.DateTimeField("更新日", default=timezone.now)
service = models.ForeignKey(Service, on_delete=models.SET_NULL, related_name="ConnectionService", null=True, blank=True)
connection_type = models.IntegerField("サービスタイプ", default=CONNECTION_EIP, choices=CONNECTION_TYPE_CHOICES)
connection_number = models.IntegerField("接続番号", default=0)
connection_comment = models.IntegerField("接続情報コメント", default=0, blank=True)
connection_type = models.CharField("接続タイプ", default=CONNECTION_EIP, choices=CONNECTION_TYPE_CHOICES, max_length=255)
connection_number = models.IntegerField("接続番号", default=1)
connection_comment = models.CharField("接続情報コメント", default="", blank=True, max_length=255)
is_active = models.BooleanField("有効", default=True)
is_open = models.BooleanField("開通", default=False)
tunnel_ip = models.ForeignKey(TunnelIP, on_delete=models.CASCADE, related_name="ConnectionTunnelIP", max_length=255)
tunnel_ip = models.ForeignKey(TunnelIP, on_delete=models.CASCADE, related_name="ConnectionTunnelIP", max_length=255, null=True, blank=True)
hope_location = models.CharField("接続希望場所", default=HOPE_LOCATION_ANYWHERE, choices=HOPE_LOCATION_CHOICES, max_length=255)
term_location = models.CharField("接続終端場所", default="", blank=True, max_length=255)
ntt_type = models.CharField("NTT接続タイプ", default=NTT_TYPE1, choices=NTT_CHOICES, max_length=255)
Expand All @@ -154,6 +160,16 @@ class Meta:
user_comment = MediumTextField("ユーザコメント", default="", blank=True)
admin_comment = MediumTextField("管理者コメント", default="", blank=True)

@property
def service_code(self):
return "%s-%s%s-%s%s" % (
self.service.group.id,
self.service.service_type,
str(self.service.service_number).zfill(3),
self.connection_type,
str(self.connection_number).zfill(3),
)

def __str__(self):
return "%s-%s%s-%s%s" % (
self.service.group.id,
Expand Down

0 comments on commit 34e4640

Please sign in to comment.