私が開発しているアプリケーションは、オンラインの料理注文です。レストランのオーナーは、そのレストランで利用可能なメニューを含むレストランを一覧表示します。私はそのようなシナリオのためのモデルを設計しました。しかし私はNameErrorのエラーが発生する私のレビューモデルで問題に直面しています.Levelクラスのインポート中に 'Restaurant'という名前が定義されていません。ImportError:名前 'レストラン'が定義されていません
コード
レストラン/ models.py
class Restaurant(models.Model):
OPEN = 1
CLOSED = 2
OPENING_STATUS = (
(OPEN, 'open'),
(CLOSED, 'closed'),
)
owner = models.ForeignKey(User)
name = models.CharField(max_length=150, db_index=True)
slug = models.SlugField(max_length=150, db_index=True)
address = models.CharField(max_length=100)
city = models.CharField(max_length=100)
phone_number = models.PositiveIntegerField()
owner_email = models.EmailField()
opening_status = models.IntegerField(choices=OPENING_STATUS, default=OPEN)
website = models.URLField(max_length=300)
features = models.ManyToManyField(Choice, related_name="restaurants_features")
timings = models.ManyToManyField(Choice, related_name="restaurants_timings")
opening_from = models.TimeField()
opening_to = models.TimeField()
facebook_page = models.URLField(max_length=200)
twitter_handle = models.CharField(max_length=15, blank=True, null=True)
other_details = models.TextField()
# votes = models.IntegerField(choices=STARS, default=5)
class Menu(models.Model):
STARS = (
(1, 'one'),
(2, 'two'),
(3, 'three'),
(4, 'four'),
(5, 'five'),
)
menu_category = models.ForeignKey(Category, related_name="menu")
restaurant = models.ForeignKey(Restaurant)
name = models.CharField(max_length=120,db_index=True)
slug = models.SlugField(max_length=120,db_index=True)
image = models.ImageField(upload_to='products/%Y/%m/%d', blank=True)
description = models.TextField(blank=True)
price = models.DecimalField(max_digits=10,decimal_places=2)
stock = models.PositiveIntegerField()
vote = models.SmallIntegerField(choices=STARS, default=5)
レビュー/ models.py
from restaurants.models import Restaurant # I am getting an error here
class Review(models.Model):
STARS = (
(1, 'one'),
(2, 'two'),
(3, 'three'),
(4, 'four'),
(5, 'five'),
)
vote = models.SmallIntegerField(choices=STARS, default=5)
user = models.ForeignKey(User)
restaurant = models.ForeignKey(Restaurant)
review = models.TextField()
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
def __str__(self):
return self.vote
はなぜこのようなエラーを取得していますか?
もう1つ質問があります。レストランには複数のメニュー項目があります。ユーザーは各メニューを評価する(評価なしの評価のみ)。そのような機能のために私のモデルは大丈夫ですか?
あなたが示したコードは、NameErrorではなくImportErrorを与えます。正確な*コードと完全なエラーを表示してください。 –
申し訳ありませんが悪いです。私は私の質問を更新しました。それはImportErrorです。あなたは完全なコードで私の質問を更新すると言っているのですか? – pythonBeginner