python - What is the proper way to update a listfield of embedded documents in mongoengine? -


I am trying to define ways to check and update the list of embedded documents in the field field. I am trying, what is the proper way to do it is the code is below. commented (commented) def define comment (embedded document): made = date timefield () text = stringfield () class post (document): comments = listField ): For existing_comment in self.comments: if comment.created == existing_comment.created and comment.text == existing_ comment.text: return true return wrong def add_or_replace_comment (self, comment): for self-contained existing_comment: if Comment. Created == existing_command Created: # How will I change? # How do I add?

Is this the right way to go about something like this?

You can use EmbeddedDoclockLilffield instead of the list of embedded documents. This way you get access to something like Filters , create or updates :

  class comment (Embedded document): created = datetimefild () text = stringfield () class post (document): comments = EmbeddedLilifffield (comment) ... def add_or_replace_comment (self, comment): existing = self.comments.filter (created = comment. Cents) if existing (no code test)         html>

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -