1 | from django.db import models
|
---|
2 |
|
---|
3 | # Create your models here.
|
---|
4 | class Foo(models.Model):
|
---|
5 | bars = models.ManyToManyField('Bar', through='FooBar')
|
---|
6 |
|
---|
7 | def __unicode__(self, ):
|
---|
8 | return str(self.pk, )
|
---|
9 |
|
---|
10 |
|
---|
11 | class Bar(models.Model):
|
---|
12 | slug = models.SlugField(unique=True)
|
---|
13 |
|
---|
14 | def __unicode__(self, ):
|
---|
15 | return str(self.pk, ) + ": " + self.slug
|
---|
16 |
|
---|
17 |
|
---|
18 | class FooBar(models.Model):
|
---|
19 | foo = models.ForeignKey('Foo')
|
---|
20 | bar = models.ForeignKey('Bar', to_field='slug', )
|
---|
21 | def __unicode__(self, ):
|
---|
22 | return "pk=%s foo=%s bar=%s" % (str(self.pk), self.foo, self.bar, )
|
---|
23 |
|
---|
24 |
|
---|
25 |
|
---|
26 | class Foo2(models.Model):
|
---|
27 | bars = models.ManyToManyField('Bar2', through='FooBar2')
|
---|
28 |
|
---|
29 | def __unicode__(self, ):
|
---|
30 | return str(self.pk, )
|
---|
31 |
|
---|
32 |
|
---|
33 | class Bar2(models.Model):
|
---|
34 | slug = models.SlugField(unique=True)
|
---|
35 |
|
---|
36 | def __unicode__(self, ):
|
---|
37 | return str(self.pk, ) + ": " + self.slug
|
---|
38 |
|
---|
39 |
|
---|
40 | class FooBar2(models.Model):
|
---|
41 | foo = models.ForeignKey('Foo2')
|
---|
42 | bar = models.ForeignKey('Bar2')
|
---|
43 | def __unicode__(self, ):
|
---|
44 | return "pk=%s foo=%s bar=%s" % (str(self.pk), self.foo, self.bar, )
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|