Commit 2630a462 authored by chirac's avatar chirac

Modele machines/interface complet

parent e200757a
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)
# -*- 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),
),
]
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment