簡體   English   中英

Django formtools和表單實例的實例變量

[英]Django formtools and instance variable for form instance

我正在使用Django formtools創建多步驟表單。 問題是我不知道如何將唯一ID傳遞給表單實例。 像這樣:

  1. 用戶進入表格第1步-即 從頭開始啟動向導。 創建唯一的隨機ID。
  2. 可以在所有步驟中訪問ID,並且ID將保持不變,直到done()。
  3. 如果用戶退回到步驟1,則ID仍將保持不變。
  4. 如果用戶從頭開始創建表格(清除所有先前的數據),則將創建一個新的ID。

但是,這怎么辦呢? 沒有初始化可利用。 另一方面,initial_dict將在所有表單實例中保持不變,並且不滿足第4點。

任何想法如何解決這個問題?

也許嘗試這樣的事情:

class MyWizardView(SessionWizardView):
    unique_id == ""

    def get(self, request, *args, **kwargs):
        """
        This method handles GET requests.

        If a GET request reaches this point, the wizard assumes that the user
        just starts at the first step or wants to restart the process.
        The data of the wizard will be resetted before rendering the first step
        """
        self.storage.reset()

        # reset the current step to the first step.
        self.storage.current_step = self.steps.first
        unique_id = # Insert ID generator here #
        return self.render(self.get_form())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM