.py文件没有在django上编译 [英] .py file is not compiled on django

查看:104
本文介绍了.py文件没有在django上编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django 1.6.1。我在模型文件夹中有一个文件名payment.py,它没有被编译成.pyc文件。即使我将文件名更改为payment_room.py,仍然不会被编译



其他模型文件已经被编译并且工作得很好。因为这样,如果我运行syncdb命令,django将不会在数据库上创建表。我使用manage.py运行validate命令,但没有返回任何错误。



N.B。
它仍然在调试&开发模式。网络尚未部署到Apache服务器。

 从django.db导入模型
从ghb_manager.models.reservation import Reservation

类付款(models.Model):
class Meta:
app_label ='ghb_manager'

PAYMENT_METHOD_CHOICES =(
('CA','Cash'),
('CR','信用'),
('TR','转移')


payment_id = models.CharField(max_length = 14,primary_key = true)
reservation_id = models.ForeignKey(Reservation)
ammount_tendered = models.DecimalField(max_digits = 19,decimal_places = 2)
payment_method = models.CharField(max_length = 20,choices = PAYMENT_METHOD_CHOICES )
payment_date = models.DateField()

def __unicode __(self):
return self.payment_id


解决方案

请检查您的models目录中的 init .py。您必须导入您在模型目录中创建的所有模型,例如:

 #__init__.py 
从付款导入付款

Django查看app.models的应用程序模型。


I'm using django 1.6.1. I got one file name "payment.py" on models folder and it's not compiled to .pyc file. Even if I changed the file name to "payment_room.py", it still won't be compiled

The other model files have been compiled already and worked pretty well.

Because of that, django won't create the table on my database if I run syncdb command. I run validate command using manage.py, but it didn't return any error.

N.B. It's still on debug & development mode. The web hasn't been deployed to apache server yet.

from django.db import models
from ghb_manager.models.reservation import Reservation

class Payment (models.Model):
    class Meta:
        app_label = 'ghb_manager'

    PAYMENT_METHOD_CHOICES = (
    ('CA', 'Cash'),
    ('CR', 'Credit'),
    ('TR', 'Transfer')
    )

    payment_id = models.CharField(max_length=14, primary_key=True)
    reservation_id = models.ForeignKey(Reservation)
    ammount_tendered = models.DecimalField(max_digits=19, decimal_places=2)
    payment_method = models.CharField(max_length=20, choices=PAYMENT_METHOD_CHOICES)
    payment_date = models.DateField()

    def __unicode__(self):
        return self.payment_id

解决方案

Please check your init.py in your models directory. You have to import all the models you create in models directory, like:

# __init__.py
from payment import Payment

Django looks into app.models for app's models.

这篇关于.py文件没有在django上编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆