Ich verwende django_tables2, um meine Tabellen in datatables zu ändern. Allerdings bin ich wirklich verwirrt darüber, wie ich damit fortfahren kann. Im meine Sicht campaigns.py
Ich habe diese (diese Datei andere 1 andere Klasse mit 2 Methoden hat):Django_tables2: Erstellen Sie Tabelle aus dem Wörterbuch
class CampaignListView(FacebookAdInit):
""" CampaignListView for viewing all the campaigns"""
def get(self, request, *args, **kwargs):
ad_account = self.get_ad_account(kwargs.get('ad_account_id'))
campaigns = self.get_campaigns(ad_account.get('id')) \
if ad_account else None
context = {'campaigns': campaigns, 'ad_account': ad_account}
return render(request, 'app/campaigns/index.html', context)
I zeige den context
Wörterbuch als Tabelle in meiner Vorlage: campaigns/index.html
mithilfe der <table>,<td> and <tr>
HTML-Tags:
<table class="table table-bordered table-striped" id="campaigns">
<thead>
<tr>
<th> #</th>
<th> Campaign Name</th>
<th> Campaign Objective</th>
<th> Campaign Effective Status</th>
</tr>
</thead>
<tbody>
{% for campaign in campaigns %}
<tr>
<td> {{ forloop.counter }} </td>
<td>
<a href="/ad_accounts/{{ ad_account.id }}/campaigns/{{ campaign.id }}/ad_sets">
{{ campaign.name }} </a>
</td>
<td> {{ campaign.objective }}</td>
<td> {{ campaign.effective_status }} </td>
</tr>
{% endfor %}
</tbody>
</table>
Nun, wie um alles in der Welt gehe ich weiter und mache daraus eine "paginierte" Datentabelle. Ive unzählige SO Fragen und this one looked helpful durchgemacht, aber wie importiere ich meine Ansicht in die tables.py
und wo platziere ich die tables.py
Datei, wenn meine Struktur ist:
folder\
migrations\
static\
templates\
app\
#a whole bunch of templates
views\
campaigns.py
__init__.py
models.py
forms.py
...
...