8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-25 00:13:45 +00:00

Modele machines/interface complet

This commit is contained in:
Gabriel Detraz 2016-07-03 16:49:29 +02:00
parent df82177a73
commit 1b8ece350c
6 changed files with 68 additions and 1 deletions

View file

@ -1,6 +1,6 @@
from django.contrib import admin
from .models import Machine, MachineType
from .models import Machine, MachineType, IpList, Interface
class MachineAdmin(admin.ModelAdmin):
list_display = ('user','type')
@ -8,5 +8,13 @@ class MachineAdmin(admin.ModelAdmin):
class MachineTypeAdmin(admin.ModelAdmin):
list_display = ('type',)
class IpListAdmin(admin.ModelAdmin):
list_display = ('ipv4',)
class InterfaceAdmin(admin.ModelAdmin):
list_display = ('machine','name','mac_address','ipv4','details')
admin.site.register(Machine, MachineAdmin)
admin.site.register(MachineType, MachineTypeAdmin)
admin.site.register(IpList, IpListAdmin)
admin.site.register(Interface, InterfaceAdmin)

View file

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import macaddress.fields
class Migration(migrations.Migration):
dependencies = [
('machines', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Interface',
fields=[
('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)),
('ipv6', models.GenericIPAddressField(protocol='IPv6')),
('mac_address', macaddress.fields.MACAddressField(integer=True)),
('details', models.CharField(max_length=255)),
('name', models.CharField(max_length=255, blank=True, unique=True)),
],
),
migrations.CreateModel(
name='IpList',
fields=[
('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)),
('ipv4', models.GenericIPAddressField(protocol='IPv4')),
],
),
migrations.AddField(
model_name='interface',
name='ipv4',
field=models.OneToOneField(null=True, to='machines.IpList', blank=True, on_delete=django.db.models.deletion.PROTECT),
),
migrations.AddField(
model_name='interface',
name='machine',
field=models.ForeignKey(to='machines.Machine', on_delete=django.db.models.deletion.PROTECT),
),
]

View file

@ -1,4 +1,5 @@
from django.db import models
from macaddress.fields import MACAddressField
from users.models import User
@ -16,4 +17,19 @@ class MachineType(models.Model):
return self.type
class Interface(models.Model):
ipv4 = models.OneToOneField('IpList', on_delete=models.PROTECT, blank=True, null=True)
ipv6 = models.GenericIPAddressField(protocol='IPv6')
mac_address = MACAddressField()
machine = models.ForeignKey('Machine', on_delete=models.PROTECT)
details = models.CharField(max_length=255)
name = models.CharField(max_length=255, unique=True, blank=True)
def __str__(self):
return self.name
class IpList(models.Model):
ipv4 = models.GenericIPAddressField(protocol='IPv4')
def __str__(self):
return self.type