Parcourir la source

Add a storage place notion

Jocelyn Delande il y a 9 ans
Parent
commit
d0d6f956bb

+ 14 - 2
hardware_provisioning/admin.py

@@ -6,7 +6,7 @@ from datetime import date
 
 from django.contrib import admin
 from django.contrib.auth import get_user_model
-from .models import ItemType, Item, Loan
+from .models import ItemType, Item, Loan, Storage
 
 
 User = get_user_model()
@@ -36,7 +36,7 @@ class ItemAdmin(admin.ModelAdmin):
     list_display = (
         'designation', 'type', 'mac_address', 'serial', 'owner',
         'buy_date', 'is_available')
-    list_filter = ('type__name', 'buy_date', OwnerFilter)
+    list_filter = ('type__name', 'storage', 'buy_date', OwnerFilter)
     search_fields = (
         'designation', 'mac_address', 'serial',
         'owner__email', 'owner__nickname',
@@ -59,3 +59,15 @@ class LoanAdmin(admin.ModelAdmin):
         queryset.filter(loan_date_end=None).update(
             loan_date_end=date.today())
     end_loan.short_description = 'Mettre fin au prêt'
+
+
+@admin.register(Storage)
+class StorageAdmin(admin.ModelAdmin):
+    list_display = ('name', 'truncated_notes')
+
+    def truncated_notes(self, obj):
+        if len(obj.notes) > 50:
+            return '{}…'.format(obj.notes[:50])
+        else:
+            return obj.note
+    truncated_notes.short_description = 'notes'

+ 27 - 0
hardware_provisioning/migrations/0006_storage.py

@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('hardware_provisioning', '0005_auto_20160405_1841'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Storage',
+            fields=[
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('name', models.CharField(max_length=100, verbose_name='nom')),
+                ('notes', models.TextField(help_text='Lisible par tous les adh\xe9rents', blank=True)),
+            ],
+            options={
+                'verbose_name': 'lieu de stockage',
+                'verbose_name_plural': 'lieux de stockage',
+            },
+            bases=(models.Model,),
+        ),
+    ]

+ 20 - 0
hardware_provisioning/migrations/0007_item_storage.py

@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('hardware_provisioning', '0006_storage'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='item',
+            name='storage',
+            field=models.ForeignKey(related_name='items', blank=True, to='hardware_provisioning.Storage', help_text='Laisser vide si inconnu', null=True, verbose_name='Lieu de stockage'),
+            preserve_default=True,
+        ),
+    ]

+ 19 - 0
hardware_provisioning/models.py

@@ -22,6 +22,11 @@ class Item(models.Model):
     type = models.ForeignKey(ItemType, verbose_name='type de matériel',
                              related_name='items')
     designation = models.CharField(max_length=100, verbose_name='désignation')
+    storage = models.ForeignKey(
+        'Storage', related_name='items',
+        verbose_name='Lieu de stockage',
+        null=True, blank=True,
+        help_text='Laisser vide si inconnu')
     mac_address = MACAddressField(
         verbose_name='addresse MAC',
         blank=True, null=True,
@@ -104,3 +109,17 @@ class Loan(models.Model):
         verbose_name_plural = 'prêts d’objets'
 
     objects = LoanQuerySet().as_manager()
+
+
+class Storage(models.Model):
+    name = models.CharField(max_length=100, verbose_name='nom')
+    notes = models.TextField(
+        blank=True,
+        help_text='Lisible par tous les adhérents')
+
+    def __unicode__(self):
+        return self.name
+
+    class Meta:
+        verbose_name = 'lieu de stockage'
+        verbose_name_plural = 'lieux de stockage'