Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Nounous
re2o
Commits
6e811ca3
Commit
6e811ca3
authored
Jul 04, 2016
by
lhark
Browse files
Simplified Room model
parent
984435ae
Changes
4
Hide whitespace changes
Inline
Side-by-side
topologie/admin.py
View file @
6e811ca3
...
...
@@ -10,7 +10,7 @@ class PortAdmin(admin.ModelAdmin):
list_display
=
(
'switch'
,
'port'
,
'room'
,
'details'
)
class
RoomAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'
building'
,
'room'
,
'number'
,
'details'
)
list_display
=
(
'
name'
,
)
admin
.
site
.
register
(
Port
,
PortAdmin
)
admin
.
site
.
register
(
Room
,
RoomAdmin
)
...
...
topologie/migrations/0010_auto_20160704_2148.py
0 → 100644
View file @
6e811ca3
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'topologie'
,
'0009_auto_20160703_1200'
),
]
operations
=
[
migrations
.
RenameField
(
model_name
=
'room'
,
old_name
=
'building'
,
new_name
=
'name'
,
),
migrations
.
AlterUniqueTogether
(
name
=
'room'
,
unique_together
=
set
([]),
),
migrations
.
RemoveField
(
model_name
=
'room'
,
name
=
'details'
,
),
migrations
.
RemoveField
(
model_name
=
'room'
,
name
=
'number'
,
),
migrations
.
RemoveField
(
model_name
=
'room'
,
name
=
'room'
,
),
]
topologie/migrations/0011_auto_20160704_2153.py
0 → 100644
View file @
6e811ca3
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'topologie'
,
'0010_auto_20160704_2148'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'room'
,
name
=
'name'
,
field
=
models
.
CharField
(
max_length
=
255
,
unique
=
True
),
),
]
topologie/models.py
View file @
6e811ca3
from
django.db
import
models
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes.fields
import
GenericForeignKey
class
Switch
(
models
.
Model
):
building
=
models
.
CharField
(
max_length
=
10
)
...
...
@@ -19,6 +19,7 @@ class Port(models.Model):
port
=
models
.
IntegerField
()
details
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
room
=
models
.
ForeignKey
(
'Room'
,
on_delete
=
models
.
PROTECT
,
blank
=
True
,
null
=
True
)
# machine_interface = models.OneToOneField('machines.Interface', on_delete=models.PROTECT, blank=True, null=True)
class
Meta
:
unique_together
=
(
'_content_type'
,
'_object_id'
)
...
...
@@ -26,7 +27,7 @@ class Port(models.Model):
_content_type
=
models
.
ForeignKey
(
ContentType
,
on_delete
=
models
.
CASCADE
,
blank
=
True
,
null
=
True
)
_object_id
=
models
.
PositiveIntegerField
(
blank
=
True
,
null
=
True
)
goto
=
GenericForeignKey
(
'_content_type'
,
'_object_id'
)
@
property
def
comefrom
(
self
):
ctype
=
ContentType
.
objects
.
get_for_model
(
self
.
__class__
)
...
...
@@ -40,14 +41,8 @@ class Port(models.Model):
return
str
(
self
.
switch
)
+
" - "
+
str
(
self
.
port
)
class
Room
(
models
.
Model
):
details
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
building
=
models
.
CharField
(
max_length
=
255
)
room
=
models
.
IntegerField
()
number
=
models
.
IntegerField
(
blank
=
True
,
null
=
True
)
class
Meta
:
unique_together
=
(
'building'
,
'room'
,
'number'
)
name
=
models
.
CharField
(
max_length
=
255
,
unique
=
True
)
def
__str__
(
self
):
return
str
(
self
.
building
)
+
str
(
self
.
room
)
+
'-'
+
str
(
self
.
number
)
return
str
(
self
.
name
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment