Versioning now uses object string representation rather than the ridiculous chain of if statements. Have improved __str methods accordingly

This commit is contained in:
David Taylor
2015-08-14 17:23:35 +03:00
committed by Tom Price
parent ece075e948
commit 27eb7cb64b
2 changed files with 15 additions and 5 deletions

View File

@@ -98,7 +98,7 @@ class Person(models.Model, RevisionMixin):
notes = models.TextField(blank=True, null=True) notes = models.TextField(blank=True, null=True)
def __str__(self): def __str__(self):
string = self.name string = "Person | {}".format(self.name)
if self.notes is not None: if self.notes is not None:
if len(self.notes) > 0: if len(self.notes) > 0:
string += "*" string += "*"
@@ -143,7 +143,7 @@ class Organisation(models.Model, RevisionMixin):
union_account = models.BooleanField(default=False) union_account = models.BooleanField(default=False)
def __str__(self): def __str__(self):
string = self.name string = "Organisation | {}".format(self.name)
if self.notes is not None: if self.notes is not None:
if len(self.notes) > 0: if len(self.notes) > 0:
string += "*" string += "*"
@@ -222,7 +222,7 @@ class Venue(models.Model, RevisionMixin):
address = models.TextField(blank=True, null=True) address = models.TextField(blank=True, null=True)
def __str__(self): def __str__(self):
string = self.name string = "Venue | {}".format(self.name)
if self.notes and len(self.notes) > 0: if self.notes and len(self.notes) > 0:
string += "*" string += "*"
return string return string
@@ -443,7 +443,17 @@ class Event(models.Model, RevisionMixin):
return reverse_lazy('event_detail', kwargs={'pk': self.pk}) return reverse_lazy('event_detail', kwargs={'pk': self.pk})
def __str__(self): def __str__(self):
return unicode(self.pk) + ": " + self.name string = ""
if self.is_rig and self.dry_hire:
string += "Dry Hire"
elif self.is_rig:
string += "Rig"
else:
string += "Non-rig"
string += " | {}".format(self.name)
return string
def clean(self): def clean(self):
if self.end_date and self.start_date > self.end_date: if self.end_date and self.start_date > self.end_date:

View File

@@ -1,4 +1,4 @@
{% load to_class_name from filters %} {% load to_class_name from filters %}
{# pass in variable "object" to this template #} {# pass in variable "object" to this template #}
<a title="{% if object.is_rig == False %}Non-rig{% elif object.dry_hire %}Dry Hire{% elif object.is_rig %}Rig{%else%}{{object|to_class_name}}{% endif %} | '{{object.name}}'" href="{{ object.get_absolute_url }}">{% if object.is_rig == False %}Non-rig{% elif object.dry_hire %}Dry Hire{% elif object.is_rig %}Rig{%else%}{{object|to_class_name}}{% endif %} | '{{object.name}}'</a> <a title="'{{ object }}'" href="{{ object.get_absolute_url }}">'{{ object }}'</a>