簡體   English   中英

如何在石墨烯mongo python中更新EmbeddedDocument的字段

[英]How to update field for EmbeddedDocument in graphene mongo python

我正在嘗試更新IgThread EmbeddedDocument的一個字段,並且發生錯誤: 'IgThread' object has no attribute 'save'

我嘗試了一些奇怪的解決方案,但都沒有用。 當前代碼中有錯誤

突變:

def mutate(self, _, **kwargs):
    ig_pk = kwargs['ig_pk']
    thread_input = kwargs['ig_thread']

    lead_ = Lead.objects(ig__pk=ig_pk).first()

    for thread in lead_.messages.ig:

        Lead.objects(
            ig__pk=ig_pk,
            messages__ig__thread_id=thread_input.thread_id,
        ).update(
            push_all__messages__ig__S__messages=new_messages,
        )

        thread.last_activity_at = thread_input.last_activity_at
        thread.save()

上級:

class Lead(Document):
    id = fields.ObjectIdField()
    messages = fields.EmbeddedDocumentField(Messages)

嵌套的EmbeddedDocument:

class Messages(EmbeddedDocument):
    ig = fields.EmbeddedDocumentListField(IgThread)

更深層次的:

class IgThread(EmbeddedDocument):
    thread_id = fields.StringField()
    last_activity_at = fields.StringField()

我想更新last_activity_at Pls,請幫助,我必須修復該錯誤,並且沒人能在辦公室幫助我解決這個問題:<

解決了! 很容易...

def mutate(self, _, **kwargs):
    ig_pk = kwargs['ig_pk']
    thread_input = kwargs['ig_thread']

    lead_ = Lead.objects(ig__pk=ig_pk).first()

    for thread in lead_.messages.ig:

        Lead.objects(
            ig__pk=ig_pk,
            messages__ig__thread_id=thread_input.thread_id,
        ).update(
            push_all__messages__ig__S__messages=new_messages,
        )

        lead_ = Lead.objects(ig__pk=ig_pk).first() <--------
        thread.last_activity_at = thread_input.last_activity_at
        lead_.save() <--------

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM