我已经被如何在我的模型中做出选择数小时难住了。Django模型选择
到目前为止,我一直在我的模型批准领域的问题。我希望被批准成为3种选择中的1种,但我所看到的是所有三种选择的元组。在“./manage.py壳”,我得到
>>> listing.objects.all()[0].approved
((u'1', u'Awaiting'), (u'2', u'No'), (u'3', u'Yes'))
我的模型:
from django.db import models
# Create your models here.
class directory(models.Model):
name = models.CharField(max_length="50")
class listing(models.Model):
name = models.CharField(max_length="50")
directory = models.ForeignKey(directory)
birthday = models.DateField()
state = models.CharField(max_length="2")
owner = models.CharField(max_length="50")
approved = (
(u'1', u'Awaiting'),
(u'2', u'No'),
(u'3', u'Yes'),
)
另外一侧的问题:但是,每当我做模型的变化,并尝试以南方迁移模式我的命令行会冻结并且永远不会完成迁移模式。任何可能的建议,为什么它冻结?它可以检测到更改,但不会完成实现它们。因为它永远不会结束,当我点击模型进行更改时,我无法通过管理面板访问我的模型,我无法加载页面。
The order in which I run the commands are
./manage.py convert_to_south myapp
./manage.py schemamigration southtut --auto
./manage.py migrate southtut (never progresses on this command after the first few lines appear)
您应该将第二部分转化为自己的问题,以便将内容保留在主题上,而不是将其作为“侧面问题”。 –
我建议你在修好模型后再尝试南迁移。另外,将上面的“myapp”更改为“southtut”,因为像我这样的其他人会接受它,想知道这是否是问题的一部分。此外,使类名称CapWords。如果你还没有阅读Python的PEP-8指南,可以阅读:http://www.python.org/dev/peps/pep-0008/#class-names – tobych