0
データを表示するフォームと、データを表示する日付/年を選択できる2つの選択ドロップダウンウィートがありますので、context
とテーブルを返します。get_initial
です現在の日付と時刻を使用するようにドロップダウンを設定します。djangoは自身のページにリダイレクトします
私の質問はPOST
要求がGET
でそれ自身のページにリダイレクトするようにする方法、アイデアは?month=1&year=2016
のようなURLにいくつかのクエリパラメータの値を設定することですが、私はどこから始めればわからないが、誰かが私を助けることができますこれを理解して、ありがとう。フォームの
from django.views.generic.edit import FormView
from django.utils import timezone
from .models import Rate
from statistics.forms import StatisticsForm
from statistics.services import StatisticsCalculation
class StatisticsView(FormView):
template_name = "statistics/invoice_statistics.html"
form_class = StatisticsForm
def get_initial(self):
initial = super(StatisticsView, self).get_initial()
initial["month_choice"] = timezone.now().month
initial["invoice_year"] = timezone.now().year
return initial
def get_context_data(self, **kwargs):
context = super(StatisticsView, self).get_context_data(**kwargs)
default_currency = Rate.EUR
currency_usd = Rate.USD
currency_gbp = Rate.GBP
context["can_view"] = self.request.user.is_superuser
context["currency"] = default_currency
context["currency_usd"] = currency_usd
context["currency_gbr"] = currency_gbp
context["statistic"] = StatisticsCalculation.\
statistic_calculation(supplier_default_currency)
context["statistic_usd"] = StatisticsCalculation. \
calculation(supplier_default_currency_usd)
context["statistic_gbp"] = StatisticsCalculation. \
statistic_calculation(supplier_default_currency_gbp)
return context
url
:
url(r'^statistic/$', login_required(views.StatisticsView.as_view()), name='statistics')
テンプレート:
<form action="" method="post">{% csrf_token %}
<div class="" id="">
<label for="{{ form.month.month_choice }}"></label>
{{ form.month_choice }}
</div>
<br>
<div class="" id="">
<label for="{{ form.year.invoice_year }}"></label>
{{ form.invoice_year }}
</div>
<br>
# rest of the html
が、それは簡単な' url'ですので、あなたが私の 'のURLを設定する方法を私に説明することができます'、私の質問を更新しましょう。 – PetarP
正しいと思われる、あなたのURLはどのようなビューに向けられていますか? –
ちょうど私が得ていることは、データをブラウズしたいときにフォームがリダイレクトされていることです。私は彼がそのページにとどまり、さらにデータを表示したいと思っています。私の質問では、私は月と年の2つのフィールドを持つ単純なフォームを持っています – PetarP