mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-16 21:12:13 +00:00
Refactored away "assets" property on "Supplier" by using "related_name" instead
This commit is contained in:
19
assets/migrations/0010_auto_20200103_2134.py
Normal file
19
assets/migrations/0010_auto_20200103_2134.py
Normal file
@@ -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'),
|
||||
),
|
||||
]
|
||||
@@ -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)
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="asset_table_body">
|
||||
{% with object.assets as object_list %}
|
||||
{% with object.assets.all as object_list %}
|
||||
{% include 'partials/asset_list_table_body.html' %}
|
||||
{% endwith %}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user