Say I have a model with many attributes that are somewhat related
class ManyFields(models.Model):
a = models.CharField(…)
b = models.CharField(…)
c = models.CharField(…)
d = models.CharField(…)
…
# This works -ish, but am unsure if it is what is convention/needed
def many_fields_simple_array(self):
return [self.a,self.b,self.c,self.d,]
and later in the view, where there isn't much real estate (say mobile), I want to just provide some sort of concatenated version of the fields. Instead of
<td>{{many_fields.a}}<td>
<td>{{many_fields.b}}</td>
<td>{{many_fields.c}}</td>
…
I would like to just have
<td>{{many_fields.many_fields_simple_array()}}<td>
and it will look AWESOME :) I can handle the rendering of HTML/text, CSS, visual part (kind of going for a red-light/green-light for each field), but I don't know the repercussions of writing a Model function or a Manager. I am unsure after reading the docs/intro.
Notes/Assumptions:
- I come from a JS/Angular world, so I would assume an array would be perfect for what I need, but I think I might be missing something
- I assume an array, because in the template I could iterate over them quite easily. Open to other suggestions