英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论