Django CMS:如何在设置 window 中从数据库中显示
Django CMS: How can I show from database in setting window
我想在设置 window 中显示数据库下拉列表中的数据。现在我正在显示硬编码数组。
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"
我想在编辑设置中显示调查Window。
如何从 db 值填充 surveys
?
试试这个
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):
categories = models.ForeignKey("Survey", help_text="Select Survey", 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"
我想在设置 window 中显示数据库下拉列表中的数据。现在我正在显示硬编码数组。
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"
我想在编辑设置中显示调查Window。
如何从 db 值填充 surveys
?
试试这个
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):
categories = models.ForeignKey("Survey", help_text="Select Survey", 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"