Add related name accesor to the tag properties model

This commit is contained in:
Roberto Rosario
2014-07-09 19:11:47 -04:00
parent 59b88de5cd
commit db15e0f85d
2 changed files with 4 additions and 3 deletions

View File

@@ -9,7 +9,8 @@ from .literals import COLOR_CHOICES, COLOR_CODES
class TagProperties(models.Model):
tag = models.ForeignKey(Tag, verbose_name=_(u'tag'))
# TODO: this should be a One to One relation not a ForeignKey
tag = models.ForeignKey(Tag, verbose_name=_(u'tag'), related_name='properties')
color = models.CharField(max_length=3, choices=COLOR_CHOICES, verbose_name=_(u'color'))
class Meta:

View File

@@ -13,7 +13,7 @@ def get_tags_inline_widget(document):
tags_template.append(u'<div class="tc">')
for tag in document.tags.all():
tags_template.append(u'<ul class="tags"><li style="background: %s;">%s</li></ul>' % (tag.tagproperties_set.get().get_color_code(), escape(tag.name)))
tags_template.append(u'<ul class="tags"><li style="background: %s;">%s</li></ul>' % (tag.properties.get().get_color_code(), escape(tag.name)))
tags_template.append(u'<div style="clear:both;"></div>')
tags_template.append(u'</div>')
@@ -46,4 +46,4 @@ def single_tag_widget(tag):
def get_single_tag_template(tag):
return '<li style="background: %s">%s</li>' % (tag.tagproperties_set.get().get_color_code(), escape(tag.name).replace(u' ', u'&nbsp;'))
return '<li style="background: %s">%s</li>' % (tag.properties.get().get_color_code(), escape(tag.name).replace(u' ', u'&nbsp;'))