Created
March 10, 2019 22:49
-
-
Save hvgab/1af2770367bd10c54c7392c766001c89 to your computer and use it in GitHub Desktop.
Dynamic ListView for Django while developing/making proof of concept
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'base.html' %} | |
{% load my_extras %} | |
{% block content %} | |
<section class="section container"> | |
<table class="table"> | |
<thead> | |
<tr> | |
{% for field in fields %} | |
<td>{{ field }}</td> | |
{% endfor %} | |
</tr> | |
</thead> | |
{% for row in object_list %} | |
<tr> | |
{% for field in fields %} | |
<td>{{ row|get_attr:field }}</td> | |
{% endfor %} | |
</tr> | |
{% endfor %} | |
</table> | |
</section> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GAME | |
class GameListView(ListView): | |
model = Game | |
template_name = 'bgb_app/generic_list.html' | |
def get_context_data(self, **kwargs): | |
context = super().get_context_data(**kwargs) | |
context['fields'] = [ | |
field.name for field in self.model._meta.get_fields() | |
] | |
return context |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very cool Thanks