| 130 | ExplicitId.drop_collection() |
| 131 | |
| 132 | class Post(Document): |
| 133 | title = StringField() |
| 134 | content = StringField() |
| 135 | active = BooleanField(default=False) |
| 136 | |
| 137 | def __unicode__(self): |
| 138 | return self.title |
| 139 | |
| 140 | @classmethod |
| 141 | def pre_bulk_insert(cls, sender, documents, **kwargs): |
| 142 | signal_output.append( |
| 143 | "pre_bulk_insert signal, %s" |
| 144 | % [ |
| 145 | (doc, {"active": documents[n].active}) |
| 146 | for n, doc in enumerate(documents) |
| 147 | ] |
| 148 | ) |
| 149 | |
| 150 | # make changes here, this is just an example - |
| 151 | # it could be anything that needs pre-validation or looks-ups before bulk bulk inserting |
| 152 | for document in documents: |
| 153 | if not document.active: |
| 154 | document.active = True |
| 155 | signal_output.append(kwargs) |
| 156 | |
| 157 | @classmethod |
| 158 | def post_bulk_insert(cls, sender, documents, **kwargs): |
| 159 | signal_output.append( |
| 160 | "post_bulk_insert signal, %s" |
| 161 | % [ |
| 162 | (doc, {"active": documents[n].active}) |
| 163 | for n, doc in enumerate(documents) |
| 164 | ] |
| 165 | ) |
| 166 | if kwargs.pop("loaded", False): |
| 167 | signal_output.append("Is loaded") |
| 168 | else: |
| 169 | signal_output.append("Not loaded") |
| 170 | signal_output.append(kwargs) |
| 171 | |
| 172 | self.Post = Post |
| 173 | Post.drop_collection() |
nothing calls this directly
no test coverage detected