From ccf0447d3a9894230d28dc9a3e680aea5fbc8957 Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@esss.se>
Date: Mon, 28 Aug 2017 14:37:47 +0200
Subject: [PATCH] Remove name column from Item

Most items won't have a name.
hostname could be added in a separate table if required.
---
 app/api/main.py          | 1 -
 app/main/views.py        | 1 -
 app/models.py            | 5 +----
 app/templates/index.html | 1 -
 4 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/app/api/main.py b/app/api/main.py
index 0765535..9bdf0b5 100644
--- a/app/api/main.py
+++ b/app/api/main.py
@@ -98,7 +98,6 @@ def patch_item(item_id):
     item = Item.query.get(item_id)
     if item is None:
         raise utils.InventoryError(f'Unknown item id: {item_id}', status_code=422)
-    item.name = data.get('name', item.name)
     item.manufacturer = utils.convert_to_model(data.get('manufacturer', item.manufacturer), Manufacturer)
     item.model = utils.convert_to_model(data.get('model', item.model), Model)
     item.location = utils.convert_to_model(data.get('location', item.location), Location)
diff --git a/app/main/views.py b/app/main/views.py
index bed5b67..f46aef8 100644
--- a/app/main/views.py
+++ b/app/main/views.py
@@ -42,7 +42,6 @@ def retrieve_items():
     items = Item.query.order_by(Item._created)
     data = [[item.id,
              item.serial_number,
-             item.name,
              utils.format_field(item.manufacturer),
              utils.format_field(item.model),
              utils.format_field(item.location),
diff --git a/app/models.py b/app/models.py
index 40680d5..066f554 100644
--- a/app/models.py
+++ b/app/models.py
@@ -220,7 +220,6 @@ class Item(db.Model):
     _created = db.Column(db.DateTime, default=db.func.now())
     _updated = db.Column(db.DateTime, default=db.func.now(), onupdate=db.func.now())
     serial_number = db.Column(db.String(100), nullable=False)
-    name = db.Column(db.String(100))
     hash = db.Column(GUID, unique=True)
     manufacturer_id = db.Column(db.Integer, db.ForeignKey('manufacturer.id'))
     model_id = db.Column(db.Integer, db.ForeignKey('model.id'))
@@ -234,10 +233,9 @@ class Item(db.Model):
     status = db.relationship('Status', back_populates='items')
     children = db.relationship('Item', backref=db.backref('parent', remote_side=[id]))
 
-    def __init__(self, serial_number=None, name=None, manufacturer=None, model=None, location=None, status=None):
+    def __init__(self, serial_number=None, manufacturer=None, model=None, location=None, status=None):
         # All arguments must be optional for this class to work with flask-admin!
         self.serial_number = serial_number
-        self.name = name
         self.manufacturer = utils.convert_to_model(manufacturer, Manufacturer)
         self.model = utils.convert_to_model(model, Model)
         self.location = utils.convert_to_model(location, Location)
@@ -251,7 +249,6 @@ class Item(db.Model):
         return {
             'id': self.id,
             'serial_number': self.serial_number,
-            'name': self.name,
             'hash': self.hash,
             'manufacturer': utils.format_field(self.manufacturer),
             'model': utils.format_field(self.model),
diff --git a/app/templates/index.html b/app/templates/index.html
index d110d24..b70bb36 100644
--- a/app/templates/index.html
+++ b/app/templates/index.html
@@ -10,7 +10,6 @@
       <tr>
         <th>Id</th>
         <th>Serial number</th>
-        <th>name</th>
         <th>Manufacturer</th>
         <th>Model</th>
         <th>Location</th>
-- 
GitLab