| 242 | BlogPost.drop_collection() |
| 243 | |
| 244 | def test_exclude(self): |
| 245 | class User(EmbeddedDocument): |
| 246 | name = StringField() |
| 247 | email = StringField() |
| 248 | |
| 249 | class Comment(EmbeddedDocument): |
| 250 | title = StringField() |
| 251 | text = StringField() |
| 252 | |
| 253 | class BlogPost(Document): |
| 254 | content = StringField() |
| 255 | author = EmbeddedDocumentField(User) |
| 256 | comments = ListField(EmbeddedDocumentField(Comment)) |
| 257 | |
| 258 | BlogPost.drop_collection() |
| 259 | |
| 260 | post = BlogPost(content="Had a good coffee today...") |
| 261 | post.author = User(name="Test User") |
| 262 | post.comments = [ |
| 263 | Comment(title="I aggree", text="Great post!"), |
| 264 | Comment(title="Coffee", text="I hate coffee"), |
| 265 | ] |
| 266 | post.save() |
| 267 | |
| 268 | obj = BlogPost.objects.exclude("author", "comments.text").get() |
| 269 | assert obj.author is None |
| 270 | assert obj.content == "Had a good coffee today..." |
| 271 | assert obj.comments[0].title == "I aggree" |
| 272 | assert obj.comments[0].text is None |
| 273 | |
| 274 | BlogPost.drop_collection() |
| 275 | |
| 276 | def test_exclude_only_combining(self): |
| 277 | class Attachment(EmbeddedDocument): |