Better string formatting for models

Allows for easier searching in drop-downs for ForeignKeys
This commit is contained in:
Oliver 2018-05-09 00:17:39 +10:00
parent 233f093093
commit 7644617af0
4 changed files with 21 additions and 13 deletions

View File

@ -53,7 +53,7 @@ class Company(models.Model):
is_supplier = models.BooleanField(default=True)
def __str__(self):
return self.name
return "{n} - {d}".format(n=self.name, d=self.description)
def get_absolute_url(self):
return "/company/{id}/".format(id=self.id)

View File

@ -4,15 +4,28 @@
{% include 'company/tabs.html' with tab='parts' %}
<h3>Company Parts</h3>
<div class='row'>
<div class='col-sm-6'>
<h3>Supplier Parts</h3>
</div>
<div class='col-sm-6'>
<h3 class='float-right'>
<button class="btn btn-success" id='part-create'>New Supplier Part</button>
<div class="dropdown" style="float: right;">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Options
<span class="caret"></span></button>
<ul class="dropdown-menu">
</ul>
</div>
</h3>
</div>
</div>
<hr>
<table clas='table table-striped table-condensed' id='part-table'>
</table>
<div class='container-fluid'>
<button class="btn btn-success" id='part-create'>New Supplier Part</button>
</div>
{% endblock %}
{% block js_ready %}
{{ block.super }}

View File

@ -5,7 +5,7 @@
<div class='row'>
<div class='col-sm-6'>
<h3>Supplier Part</h3>
<p>{{ part.SKU }} - <a href="{% url 'company-detail' part.supplier.id %}">{{ part.supplier.name }}</a></p>
<p>{{ part.SKU }} - <a href="{% url 'company-detail-parts' part.supplier.id %}">{{ part.supplier.name }}</a></p>
</div>
<div class='col-sm-6'>
<h3>

View File

@ -145,12 +145,7 @@ class Part(models.Model):
notes = models.TextField(blank=True)
def __str__(self):
if self.IPN:
return "{name} ({ipn})".format(
ipn=self.IPN,
name=self.name)
else:
return self.name
return "{n} - {d}".format(n=self.name, d=self.description)
class Meta:
verbose_name = "Part"