им делать в лом с Scrapy и моя модель на Джанго является:внешних ключей на Scrapy
class Creative(models.Model):
name = models.CharField(max_length=200)
picture = models.CharField(max_length=200, null = True)
class Project(models.Model):
title = models.CharField(max_length=200)
description = models.CharField(max_length=500, null = True)
creative = models.ForeignKey(Creative)
class Image(models.Model):
url = models.CharField(max_length=500)
project = models.ForeignKey(Project)
И моя SCRAPY модель:
from scrapy.contrib.djangoitem import DjangoItem
from app.models import Project, Creative
class ProjectItems(DjangoItem):
django_model = Project
class CreativeItems(DjangoItem):
django_model = Creative
Так что, когда я сохраняю:
creative["name"] = hxs.select('//*[@id="owner"]/text()').extract()[0]
picture = hxs.select('//*[@id="owner-icon"]/a/img/@src').extract()
if len(picture)>0:
creative["picture"] = picture[0]
creative.save()
# Extract title and description of the project
project["title"] = hxs.select('//*[@id="project-title"]/text()').extract()[0]
description = hxs.select('//*[@class="project-description"]/text()').extract()
if len(description)>0:
project["description"] = description[0]
project["creative"] = creative
project.save()
Я получил ошибку:
Project.creative" must be a "Creative" instance.
Итак, как я могу добавить ключевое значение для scrapy?
Является ли 'творческим 'создается путем создания экземпляра' Creative'? – kolen
Можете ли вы включить всю трассировку ошибки? –