File tree Expand file tree Collapse file tree 3 files changed +4
-7
lines changed Expand file tree Collapse file tree 3 files changed +4
-7
lines changed Original file line number Diff line number Diff line change @@ -5,5 +5,5 @@ class Book(models.Model):
5
5
title = models .CharField (max_length = 100 )
6
6
7
7
class Chapter (models .Model ):
8
- book = models .ForeignKey (Book )
8
+ book = models .ForeignKey (Book , on_delete = models . CASCADE )
9
9
title = models .CharField (max_length = 100 )
Original file line number Diff line number Diff line change @@ -15,11 +15,8 @@ def setup():
15
15
from query_prefetch_related .models import Book , Author
16
16
for i in range (0 , 20 ):
17
17
a = Author .objects .create (author = "Author %s" % i )
18
- bset = set ()
19
- for j in range (0 , 3 ):
20
- b = Book .objects .create (title = "Title %s" % j )
21
- bset .add (b )
22
- a .books = bset
18
+ books = [Book .objects .create (title = "Title %s" % j ) for j in range (0 , 3 )]
19
+ a .books .add (* books )
23
20
24
21
if VERSION < (1 , 4 ):
25
22
print ("SKIP: prefetch_related not supported before Django 1.4" )
Original file line number Diff line number Diff line change 3
3
4
4
class Book (models .Model ):
5
5
title = models .CharField (max_length = 100 )
6
- author = models .ForeignKey ('Author' )
6
+ author = models .ForeignKey ('Author' , on_delete = models . CASCADE )
7
7
8
8
class Author (models .Model ):
9
9
author = models .CharField (max_length = 100 )
You can’t perform that action at this time.
0 commit comments