1 | __test__ = {"doctest": """
|
---|
2 |
|
---|
3 | >>> a1 = Author.objects.create(name='Albert Einstein')
|
---|
4 | >>> isinstance(Book.objects, CustomManager)
|
---|
5 | True
|
---|
6 | >>> isinstance(a1.book_set, CustomManager)
|
---|
7 | True
|
---|
8 |
|
---|
9 | >>> b1 = Book.objects.create(author=a1, title='How to be smart',
|
---|
10 | ... extra_arg='extra argument detected')
|
---|
11 | [extra argument detected]
|
---|
12 |
|
---|
13 | >>> b2 = a1.book_set.create(title='How to program',
|
---|
14 | ... extra_arg='extra argument detected')
|
---|
15 | [extra argument detected]
|
---|
16 |
|
---|
17 | """}
|
---|
18 |
|
---|
19 |
|
---|
20 | from django.db import models
|
---|
21 |
|
---|
22 |
|
---|
23 | class CustomManager(models.Manager):
|
---|
24 |
|
---|
25 | def create(self, **kwargs):
|
---|
26 | print '[%s]' % kwargs.pop('extra_arg', '')
|
---|
27 | return super(CustomManager, self).create(**kwargs)
|
---|
28 |
|
---|
29 |
|
---|
30 | class Author(models.Model):
|
---|
31 | name = models.CharField(max_length=10)
|
---|
32 |
|
---|
33 |
|
---|
34 | class Book(models.Model):
|
---|
35 | title = models.CharField(max_length=10)
|
---|
36 | author = models.ForeignKey(Author)
|
---|
37 | objects = CustomManager()
|
---|