Django模型通过Python解释器导入问题

时间:2016-06-24 04:41:01

标签: django-models

我试图通过Python解释器(manage.py shell)向我的字段添加数据。我可以导入其他两个模型(Tag,Startup),但是Newslink模型会抛出错误:

...
Traceback (most recent call last):
      File "/usr/lib/python3.5/code.py line 91, in runcode
        exec(code, self.locals)
      File "<console>", line1 in <module>
    ImportError: cannot import name 'Newslink'

输入Python解释器:

from organizer.models import Tag
from organizer.models import Startup
from organizer.models import Newslink  <--- issue

这是我的/organizer/models.py文件:

    from django.db import models

    class Tag(models.Model):
        name = models.CharField(max_length=31,unique = True)
        slug = models.SlugField(
             max_length=31,
             unique = True, 
             help_text ="A label for URL config.")
        def __str__(self):
            return self.name.title()
        class Meta:
            ordering = ['name']


    class Startup(models.Model):
        name = models.CharField(
            max_length=31
            ,db_index= True)
        slug =  models.SlugField(
            max_length= 31,
            unique = True,
            help_text = "A label for URL config.")
        description = models.TextField()
        founded_date = models.DateField('date founded')
        contact = models.EmailField()
        website = models.URLField(max_length =255)
        tags = models.ManyToManyField(Tag)
        def __str__(self):
            return self.name
        class Meta:
            ordering = ['name']
            get_latest_by = 'founded_date'

    class NewsLink(models.Model):
        title = models.CharField(max_length=63)
        pub_date = models.DateField('date published')
        link = models.URLField(max_length=255)
        startup = models.ForeignKey(Startup)

        def __str__ (self):
            return"{}:{}".format (self.startup, self.title)
        class Meta:
            verbose_name = 'news article'
            ordering = ['-pub_date']
            get_latest_by = 'pub_date'

0 个答案:

没有答案