parts/django/tests/modeltests/many_to_many/models.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     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',)