PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 10ms RepoModel.GetById 30ms app.codeStats 0ms

/tests/regressiontests/generic_relations_regress/models.py

https://code.google.com/p/mango-py/
Python | 79 lines | 60 code | 18 blank | 1 comment | 0 complexity | c85ca7c52d4b97f711c43c810cd6cd87 MD5 | raw file
 1from django.db import models
 2from django.contrib.contenttypes import generic
 3from django.contrib.contenttypes.models import ContentType
 4
 5__all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address', 
 6           'CharLink', 'TextLink', 'OddRelation1', 'OddRelation2', 
 7           'Contact', 'Organization', 'Note')
 8
 9class Link(models.Model):
10    content_type = models.ForeignKey(ContentType)
11    object_id = models.PositiveIntegerField()
12    content_object = generic.GenericForeignKey()
13
14    def __unicode__(self):
15        return "Link to %s id=%s" % (self.content_type, self.object_id)
16
17class Place(models.Model):
18    name = models.CharField(max_length=100)
19    links = generic.GenericRelation(Link)
20
21    def __unicode__(self):
22        return "Place: %s" % self.name
23
24class Restaurant(Place):
25    def __unicode__(self):
26        return "Restaurant: %s" % self.name
27
28class Address(models.Model):
29    street = models.CharField(max_length=80)
30    city = models.CharField(max_length=50)
31    state = models.CharField(max_length=2)
32    zipcode = models.CharField(max_length=5)
33    content_type = models.ForeignKey(ContentType)
34    object_id = models.PositiveIntegerField()
35    content_object = generic.GenericForeignKey()
36
37    def __unicode__(self):
38        return '%s %s, %s %s' % (self.street, self.city, self.state, self.zipcode)
39
40class Person(models.Model):
41    account = models.IntegerField(primary_key=True)
42    name = models.CharField(max_length=128)
43    addresses = generic.GenericRelation(Address)
44
45    def __unicode__(self):
46        return self.name
47
48class CharLink(models.Model):
49    content_type = models.ForeignKey(ContentType)
50    object_id = models.CharField(max_length=100)
51    content_object = generic.GenericForeignKey()
52
53class TextLink(models.Model):
54    content_type = models.ForeignKey(ContentType)
55    object_id = models.TextField()
56    content_object = generic.GenericForeignKey()
57
58class OddRelation1(models.Model):
59    name = models.CharField(max_length=100)
60    clinks = generic.GenericRelation(CharLink)
61
62class OddRelation2(models.Model):
63    name = models.CharField(max_length=100)
64    tlinks = generic.GenericRelation(TextLink)
65
66# models for test_q_object_or:
67class Note(models.Model):
68    content_type = models.ForeignKey(ContentType)
69    object_id = models.PositiveIntegerField()
70    content_object = generic.GenericForeignKey()
71    note = models.TextField()
72
73class Contact(models.Model):
74    notes = generic.GenericRelation(Note)
75
76class Organization(models.Model):
77    name = models.CharField(max_length=255)
78    contacts = models.ManyToManyField(Contact, related_name='organizations')
79