diff --git a/assets/migrations/0010_auto_20200103_2134.py b/assets/migrations/0010_auto_20200103_2134.py new file mode 100644 index 00000000..91d2a131 --- /dev/null +++ b/assets/migrations/0010_auto_20200103_2134.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.13 on 2020-01-03 21:34 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0009_auto_20200102_1933_squashed_0011_auto_20200102_2040'), + ] + + operations = [ + migrations.AlterField( + model_name='asset', + name='purchased_from', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='assets', to='assets.Supplier'), + ), + ] diff --git a/assets/models.py b/assets/models.py index bd3d2615..f152a39a 100644 --- a/assets/models.py +++ b/assets/models.py @@ -54,14 +54,6 @@ class Supplier(models.Model, RevisionMixin): def __str__(self): return self.name - @property - def assets(self): - p = [] - for e in Asset.objects.filter(purchased_from=self): - p.append(e) - - return p - class Connector(models.Model): description = models.CharField(max_length=80) @@ -89,7 +81,7 @@ class Asset(models.Model, RevisionMixin): category = models.ForeignKey(to=AssetCategory, on_delete=models.CASCADE) status = models.ForeignKey(to=AssetStatus, on_delete=models.CASCADE) serial_number = models.CharField(max_length=150, blank=True) - purchased_from = models.ForeignKey(to=Supplier, on_delete=models.CASCADE, blank=True, null=True) + purchased_from = models.ForeignKey(to=Supplier, on_delete=models.CASCADE, blank=True, null=True, related_name="assets") date_acquired = models.DateField() date_sold = models.DateField(blank=True, null=True) purchase_price = models.DecimalField(blank=True, null=True, decimal_places=2, max_digits=10) diff --git a/assets/templates/supplier_detail.html b/assets/templates/supplier_detail.html index ddbb7817..a7889611 100644 --- a/assets/templates/supplier_detail.html +++ b/assets/templates/supplier_detail.html @@ -44,7 +44,7 @@ - {% with object.assets as object_list %} + {% with object.assets.all as object_list %} {% include 'partials/asset_list_table_body.html' %} {% endwith %}