如何在Contentful中更新条目?

huangapple go评论69阅读模式
英文:

How do I update entry in Contentful?

问题

Sure, here is the translated code portion:

def update_entry(contentful_id, car_id):
    entry = environment.entries().find(contentful_id)
    entry.fields['featuredImage'] = {
        'en-US': {
            'sys': {
                'type': 'Link',
                'linkType': 'Asset',
                'id': str(car_id) + '_featured_image'
            }
        }
    }
    time.sleep(10)
    entry.save()
    print("entry updated")

Regarding your question about publishing the entry again, you may need to publish it again if you want the changes to be reflected in the published version of the entry. It depends on your specific Contentful workflow and whether you want the updated content to be visible to your audience.

英文:
def update_entry(contentful_id, car_id):
    entry = environment.entries().find(contentful_id)
    entry.fields['featuredImage'] = {
            'en-US': {
                'sys': {
                    'type': 'Link',
                    'linkType': 'Asset',
                    'id': str(car_id) + '_featured_image'
                }
            }
    }
    time.sleep(10)
    entry.save()
    print("entry updated")

I used this code and I couldn't make it.

I have to update a field featuredImage which is a link to the asset. An asset's link is like I created it (str(car_id) + '_featured_image').

My main plan was to retrieve an entry from Contentful using ID on Contentful, add a link to the asset field, and save it. It is not working.

Also, should I publish the entry again?

答案1

得分: 2

def update_entry(contentful_id, assedId):
    entry = environment.entries().find(contentful_id)
    fields = entry.fields()

    fields['featuredImage'] = {
        'sys': {
            'type': 'Link',
            'linkType': 'Asset',
            'id': assedId
        }
    }
    
    entry.update()
    entry.save()
    entry.publish()
    time.sleep(2)
英文:
    def update_entry(contentful_id, assedId):
    entry = environment.entries().find(contentful_id)
    fields = entry.fields()

    fields['featuredImage'] = {
                'sys': {
                'type': 'Link',
                'linkType': 'Asset',
                'id': assedId
            }
    }
    
    entry.update()
    entry.save()
    entry.publish()
    time.sleep(2)

Okay so this is how I updated and published the entry in Contentful

huangapple
  • 本文由 发表于 2023年4月19日 18:37:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76053530.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定