-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
142 lines (108 loc) · 5.4 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from __future__ import unicode_literals
from django.utils.encoding import python_2_unicode_compatible
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
# connection models
class CnxServerProcessor(models.Model):
id_cnx_server_processor = models.AutoField(primary_key=True)
ref_server = models.ForeignKey('Server')
ref_processor = models.ForeignKey('Processor')
nbr_processor = models.IntegerField(verbose_name=_('number of processors'), default=1)
class Meta:
verbose_name = _('processor')
verbose_name_plural = _('processors')
class CnxServerGraphicCard(models.Model):
id_cnx_server_graphicCard = models.AutoField(primary_key=True)
ref_server = models.ForeignKey('Server')
ref_graphic_card = models.ForeignKey('GraphicCard')
nbr_graphic_card = models.IntegerField(verbose_name=_('number of graphic cards'), default=1)
class Meta:
verbose_name = _('graphic card')
verbose_name_plural = _('graphic cards')
class CnxServerHardDrive(models.Model):
id_cnx_server_hardDrive = models.AutoField(primary_key=True)
ref_server = models.ForeignKey('Server')
ref_hard_drive = models.ForeignKey('HardDrive')
nbr_hard_drive = models.IntegerField(verbose_name=_('number of hard drive'), default=1)
class Meta:
verbose_name = _('hard drive')
verbose_name_plural = _('hard drives')
# end of connection models
@python_2_unicode_compatible
class Processor(models.Model):
id_processor = models.AutoField(primary_key=True)
manufacturer = models.CharField(verbose_name=_('manufacturer'), max_length=255)
type_processor = models.CharField(verbose_name=_('type'), max_length=255)
class Meta:
verbose_name = _('processor')
verbose_name_plural = _('processors')
def __str__(self):
return self.manufacturer + " " + self.type_processor
@python_2_unicode_compatible
class GraphicCard(models.Model):
id_graphic_card = models.AutoField(primary_key=True)
manufacturer = models.CharField(verbose_name=_('manufacturer'), max_length=255)
type_graphic_card = models.CharField(verbose_name=_('type'), max_length=255)
memory_size = models.IntegerField(verbose_name=_('memory size'), help_text=_('in mb'), blank=True, null=True)
class Meta:
verbose_name = _('graphic card')
verbose_name_plural = _('graphic cards')
def __str__(self):
return self.manufacturer + " " + self.type_graphic_card
@python_2_unicode_compatible
class HardDrive(models.Model):
id_hard_drive = models.AutoField(primary_key=True)
size = models.IntegerField(verbose_name=_('size'), help_text=_('in gb'), unique=True)
flash_drive = models.BooleanField(verbose_name=_('ssd'), default=False)
class Meta:
verbose_name = _('hard drive')
verbose_name_plural = _('hard drives')
def __str__(self):
return str(self.size)
@python_2_unicode_compatible
class Localisation(models.Model):
id_localisation = models.AutoField(primary_key=True)
localisation_name = models.CharField(max_length=255, verbose_name=_('localisation name'))
class Meta:
verbose_name = _('localisation')
verbose_name_plural = _('localisations')
def __str__(self):
return self.localisation_name
@python_2_unicode_compatible
class Computer(models.Model):
id_computer = models.AutoField(primary_key=True)
serial = models.IntegerField(verbose_name=_('serial_number'), unique=True, blank=True, null=True)
name = models.CharField(verbose_name=_('name'), max_length=255, blank=True, null=True)
usage_note = models.TextField(verbose_name=_('usage note'), blank=True, null=True)
memory_size = models.IntegerField(verbose_name=_('memory size'), help_text=_('in mb'))
ref_user = models.ForeignKey(User, verbose_name=_('user'), blank=True, null=True)
ref_localisation = models.ForeignKey(Localisation, verbose_name=_('localisation'))
class Meta:
verbose_name = _('computer')
verbose_name_plural = _('computers')
def __str__(self):
return self.name
class Desktop(Computer):
ref_processor = models.ForeignKey(Processor, verbose_name=_('processor'))
ref_graphic_card = models.ForeignKey(GraphicCard, verbose_name=_('graphic card'))
ref_hard_drive = models.ForeignKey(HardDrive, verbose_name=_('hard drive'), help_text=_('in gb'))
class Meta:
verbose_name = _('desktop')
verbose_name_plural = _('desktops')
class Laptop(Computer):
ref_processor = models.ForeignKey(Processor, verbose_name=_('processor'))
ref_graphic_card = models.ForeignKey(GraphicCard, verbose_name=_('graphic card'))
ref_hard_drive = models.ForeignKey(HardDrive, verbose_name=_('hard drive'), help_text=_('in gb'))
class Meta:
verbose_name = _('laptop')
verbose_name_plural = _('laptops')
class Server(Computer):
ref_processor = models.ManyToManyField(Processor, through='CnxServerProcessor', verbose_name=_('processor'))
ref_graphic_card = models.ManyToManyField(GraphicCard, through='CnxServerGraphicCard',
verbose_name=_('graphic card'))
ref_hard_drive = models.ManyToManyField(HardDrive, through='CnxServerHardDrive', verbose_name=_('hard drive'),
help_text=_('in gb'))
class Meta:
verbose_name = _('server')
verbose_name_plural = _('servers')