0
我想在設置窗口中從數據庫的下拉菜單中顯示數據。現在我從硬編碼數組顯示。Django CMS:如何從設置窗口中的數據庫中顯示
MY_CHOICES = (
('a', 'Cat1'),
('b', 'Cat2'),
)
categories = models.CharField("Survey", help_text="Select Survey", choices=MY_CHOICES, max_length=3, blank=True)
models.py
# encoding: utf-8
from cms.models import CMSPlugin, python_2_unicode_compatible
from django.db import models
from django.core.exceptions import ValidationError
from cms.models import CMSPlugin
class Survey(models.Model):
name = models.CharField(max_length=400)
description = models.TextField()
def __unicode__(self):
return (self.name)
def questions(self):
if self.pk:
return Question.objects.filter(survey=self.pk)
else:
return None
class SurveyPluginModel(CMSPlugin):
MY_CHOICES = (
('a', 'Cat1'),
('b', 'Cat2'),
)
categories = models.CharField("Survey", help_text="Select Survey", choices=MY_CHOICES, max_length=3, blank=True)
name = models.CharField("Survey Name", max_length=255, default='Survey Name',
help_text='Enter Survey Name')
description = models.CharField("Survey Description", max_length=500, blank=True, help_text='Write Description here')
def __str__(self):
return "Returning some Survey Text"
我想告訴調查編輯設置窗口。
如何從db值填入surveys
?
可能是用戶ForeignKey的領域或ManyToManyField? – Amar
你能詳細說明一下嗎? – Volatil3
我假設你想將你的選擇保存到數據庫而不是定義的元組中? – Amar