equal
deleted
inserted
replaced
|
1 """ |
|
2 5. Many-to-many relationships |
|
3 |
|
4 To define a many-to-many relationship, use ``ManyToManyField()``. |
|
5 |
|
6 In this example, an ``Article`` can be published in multiple ``Publication`` |
|
7 objects, and a ``Publication`` has multiple ``Article`` objects. |
|
8 """ |
|
9 |
|
10 from django.db import models |
|
11 |
|
12 class Publication(models.Model): |
|
13 title = models.CharField(max_length=30) |
|
14 |
|
15 def __unicode__(self): |
|
16 return self.title |
|
17 |
|
18 class Meta: |
|
19 ordering = ('title',) |
|
20 |
|
21 class Article(models.Model): |
|
22 headline = models.CharField(max_length=100) |
|
23 publications = models.ManyToManyField(Publication) |
|
24 |
|
25 def __unicode__(self): |
|
26 return self.headline |
|
27 |
|
28 class Meta: |
|
29 ordering = ('headline',) |