Re: Display only model fields that are non-empty

2012-10-11 Thread Jonathan Baker
I just used the following code on a project to solve the problem you're describing: models.py class SomeModel(models.Model): ... def get_fields(self): return [(field.name, field.value_to_string(self)) for field in SomeModel._meta.fields if field.value_to_string(self) is not None]

Re: Display only model fields that are non-empty

2012-10-11 Thread Kurtis Mullins
There's a couple of ways, assuming you're talking about in the template. One example would simply be: {% if object.fieldname %} {{ object.fieldname }} {% endif %} Another example might be: {{ object.fieldname|default:"" }} But it doesn't allow for much formatting of an empty field. If you wan

Display only model fields that are non-empty

2012-10-11 Thread Keir Lawson
Hello, I was wondering what the most elegant way (using a DetailView or similar) to display the fields of a model, excluding those that are empty? Thanks Keir -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web