From 05101c7bba2a472888693b6c82b982a58659a697 Mon Sep 17 00:00:00 2001 From: Darian Moody Date: Sun, 12 Jun 2011 01:41:09 -0300 Subject: [PATCH] Fixed DjangoItem to work properly with auto-generated fields (such as the primary key); it will now ignore those that have had the auto_created flag set - this now allows us to work with custom primary keys as the previous way ignored a custom primary key field. --- scrapy/contrib_exp/djangoitem.py | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) --- scrapy/contrib_exp/djangoitem.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scrapy/contrib_exp/djangoitem.py b/scrapy/contrib_exp/djangoitem.py index dfef58dac..1abe98bfd 100644 --- a/scrapy/contrib_exp/djangoitem.py +++ b/scrapy/contrib_exp/djangoitem.py @@ -11,8 +11,7 @@ class DjangoItemMeta(ItemMeta): cls._model_fields = [] cls._model_meta = cls.django_model._meta for model_field in cls._model_meta.fields: - # XXX: for now we're treating each PK as autogenerated field - if model_field != cls._model_meta.pk: + if model_field.auto_created == False: if model_field.name not in cls.fields: cls.fields[model_field.name] = Field() cls._model_fields.append(model_field.name) @@ -31,4 +30,3 @@ class DjangoItem(Item): if commit: model.save() return model -