Ticket #15161: models.py

File models.py, 1.1 KB (added by adehnert, 14 years ago)

Example models.py to reproduce

Line 
1from django.db import models
2
3# Create your models here.
4class Foo(models.Model):
5 bars = models.ManyToManyField('Bar', through='FooBar')
6
7 def __unicode__(self, ):
8 return str(self.pk, )
9
10
11class Bar(models.Model):
12 slug = models.SlugField(unique=True)
13
14 def __unicode__(self, ):
15 return str(self.pk, ) + ": " + self.slug
16
17
18class 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
26class Foo2(models.Model):
27 bars = models.ManyToManyField('Bar2', through='FooBar2')
28
29 def __unicode__(self, ):
30 return str(self.pk, )
31
32
33class Bar2(models.Model):
34 slug = models.SlugField(unique=True)
35
36 def __unicode__(self, ):
37 return str(self.pk, ) + ": " + self.slug
38
39
40class 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
Back to Top