我已經被如何在我的模型中做出選擇數小時難住了。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