私はテーブルにいくつかのデータを表示している小さなフォームを構築しています。それに加えて、私は2つのdropdown
を持っています。テーブルで見たい。django形式のデータを公開する
私の質問は、私はCBV FormView
を使用していることに注意してください、私の見解では、これを処理する方法が少し混乱している、私はdjango
フォームが要求を取得し使用して、現在の月と年をdropdown
を取り込むことができる方法です。
私はこの form.py
from django import forms
import datetime
class StatisticsForm(forms.Form):
"""TODO: Simple form with two field, one for year
other for month, so user can list Statistics for
current month and year.
:returns: TODO"""
invoice_month = forms.CharField(label="month", max_length=225)
invoice_year = forms.CharField(label="year", max_length=225)
def get_initial(self):
initial = super(StatisticsForm, self).get_initial()
initial["invoice_month"] = datetime.date.today()
initial["invoice_year"] = datetime.date.today()
return initial
のようなものを試してみたし、私の見解では、私はテーブルを表示していますし、私は残りの部分を行う必要があります。
view.py
from django.views.generic.edit import FormView
from .models import Rate
from statistics.forms import StatisticsForm
from statistics.services import StatisticsCalculation
class StatisticsView(FormView):
"""
TODO: We need to handle
Total Invoice - no matter how old, basically all of them
Current month Total Invoice
"""
template_name = "statistics/invoice_statistics.html"
form_class = StatisticsForm
def get_context_data(self, **kwargs):
context = super(StatisticsView, self).get_context_data(**kwargs)
def_currency = Rate.EUR
context["can_view"] = self.request.user.is_superuser
context["currency"] = def_currency
context["supplier_statistic"] = StatisticsCalculation.statistic_calculation(default_currency)
return context
は、thatsの。 – PetarP
は((https://django-select2.readthedocs.io/en/latest/django_select2.html#django_select2.forms.Select2Widget)[ちょうど形でウィジェットを指定]、あなたは 'ジャンゴ・select2'を使用していると仮定すると、他のすべてのインストールドキュメントに従ってください)。 – Anonymous
いいえ、私は標準ライブラリを使用しています – PetarP