PageRenderTime 54ms CodeModel.GetById 50ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modeltests/many_to_many/models.py

https://code.google.com/p/mango-py/
Python | 29 lines | 14 code | 7 blank | 8 comment | 0 complexity | 2432cc22822222d5b61aeac8d72eab78 MD5 | raw file
 1"""
 25. Many-to-many relationships
 3
 4To define a many-to-many relationship, use ``ManyToManyField()``.
 5
 6In this example, an ``Article`` can be published in multiple ``Publication``
 7objects, and a ``Publication`` has multiple ``Article`` objects.
 8"""
 9
10from django.db import models
11
12class 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
21class 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',)