0

我正在尝试更新我的应用程序以使用django-polymorphic. 在尝试进行迁移时,我遇到了一个我不太了解的错误。我刚刚改为DashableModel继承自PolymorphicModel而不是,models.Model我不知道如何处理这个错误。

  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
    utility.execute()
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 325, in execute
    django.setup()
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/srv/www/apps/jobboard/models.py", line 280, in <module>
    class JobPost(SiteModel, OrderableMixIn, DashableModel):
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/base.py", line 189, in __new__
    new_class.add_to_class(obj_name, obj)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/base.py", line 324, in add_to_class
    value.contribute_to_class(cls, name)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 2549, in contribute_to_class
    self.rel.through = create_many_to_many_intermediary_model(self, cls)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 2106, in create_many_to_many_intermediary_model
    db_constraint=field.rel.db_constraint,
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/base.py", line 189, in __new__
    new_class.add_to_class(obj_name, obj)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/base.py", line 324, in add_to_class
    value.contribute_to_class(cls, name)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1772, in contribute_to_class
    super(ForeignObject, self).contribute_to_class(cls, name, virtual_only=virtual_only)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 313, in contribute_to_class
    add_lazy_relation(cls, self, other, resolve_related_class)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 86, in add_lazy_relation
    operation(field, model, cls)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 312, in resolve_related_class
    field.do_related_class(model, cls)
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 355, in do_related_class
    self.set_attributes_from_rel()
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 345, in set_attributes_from_rel
    self.rel.set_field_name()
  File "/root/.virtualenvs/mysite/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1426, in set_field_name
    self.field_name = self.field_name or self.to._meta.pk.name
AttributeError: 'NoneType' object has no attribute 'name'

模型.py

class DashableModel(PolymorphicModel, StarrableMixin):
    featured = models.BooleanField(default=False)
    sponsored = models.BooleanField(default=False)

    @property
    def sponsored_by_text(self):
        return "Sponsored"

    class Meta:
        abstract = True

class JobPost(SiteModel, OrderableMixIn, DashableModel):
    title = models.CharField(max_length=200)
    slug = models.SlugField(unique=True, max_length=100, blank=True)
    status = models.CharField(max_length=4, choices=JOB_POST_PUB_STATUS)
    topics = models.ManyToManyField(Topic, blank=True)

    # Relevant Information
    start_date = models.DateField()
    end_date = models.DateField()
    tier = models.IntegerField(blank=False, default=0)
    stickied_until = models.DateField(blank=True, null=True)

    # Newsletter start/end dates
    ns_start_date = models.DateField(blank=True, null=True, help_text="Start appearing in newsletter on this date")
    ns_end_date = models.DateField(blank=True, null=True, help_text="Last date that it appears in newsletter")

    date_created = models.DateField(auto_now_add=True)
    date_last_updated = models.DateField(blank=True, null=True)
    ip_created = models.GenericIPAddressField(blank=True, null=True)
    ip_last_updated = models.GenericIPAddressField(blank=True, null=True)

    company_name = models.CharField(max_length=200)
    company_url = models.URLField(blank=True, null=True, )

    job_type = models.CharField(blank=False, null=False, max_length=20, choices=JOB_TYPE)
    teaser = models.TextField(blank=True, default="")
    company_description = RichTextField(blank=True, config_name='baby_with_lists')
    job_description = RichTextField(blank=True, config_name='baby_with_lists')
    qualifications = RichTextField(blank=True, config_name='baby_with_lists')
    application_instructions = RichTextField(blank=True, config_name='baby_with_lists')

    apply_url = models.URLField(blank=True, null=True, )
    apply_email = models.EmailField(blank=True, null=True)

    country = models.CharField(max_length=200, default='USA', choices=COUNTRIES)
    city = models.CharField(max_length=200, blank=True, null=True, help_text='City, Town or Neighborhood')
    usa_state = us_models.USStateField(blank=True, null=True)
    # address = models.CharField(max_length=200, blank=True, null=True)

    #The person who posted the job
    poster_name = models.CharField(max_length=200, null=True, blank=True)
    poster_email = models.EmailField(null=True, blank=True)
    poster_phone = us_models.PhoneNumberField(blank=True, null=True)

    #Credit Card Info
    cc_last_four = models.CharField(max_length=4, blank=True, null=True)
    cc_receipt = models.CharField(max_length=200, blank=True, null=True)
    cc_name = models.CharField(max_length=200, blank=True, null=True)
    stripe_token = models.CharField(max_length=200, blank=True, null=True)
    stripe_customer_id = models.CharField(max_length=200, blank=True, null=True)
    stripe_notes = models.TextField(blank=True, null=True)
    last_charged = models.DateTimeField(blank=True, null=True)

    # Hash for edit url
    edit_token = models.CharField(max_length=150, blank=True, null=True, unique=True, default=None)

    # For jobs coming from a feed:
    from_feed = models.ForeignKey(JobFeed, null=True, blank=True)
    # Name of job source e.g. 'acullen'
    from_source = models.CharField(max_length=100, null=True, blank=True)

    objects = getSiteManager()
    all_sites = models.Manager()
    live_posts = LiveJobPostManager()
4

0 回答 0