2009-04-03 21:52:14 +02:00
|
|
|
from django.contrib.contenttypes import generic
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2011-10-13 23:34:56 +02:00
|
|
|
from django.db import models
|
2012-08-12 12:32:08 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2011-10-13 23:34:56 +02:00
|
|
|
|
2009-04-03 21:52:14 +02:00
|
|
|
|
2011-10-13 23:34:56 +02:00
|
|
|
__all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address',
|
|
|
|
'CharLink', 'TextLink', 'OddRelation1', 'OddRelation2',
|
2010-02-10 20:21:52 +01:00
|
|
|
'Contact', 'Organization', 'Note')
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2009-04-03 21:52:14 +02:00
|
|
|
class Link(models.Model):
|
|
|
|
content_type = models.ForeignKey(ContentType)
|
|
|
|
object_id = models.PositiveIntegerField()
|
|
|
|
content_object = generic.GenericForeignKey()
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2009-04-03 21:52:14 +02:00
|
|
|
return "Link to %s id=%s" % (self.content_type, self.object_id)
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2009-04-03 21:52:14 +02:00
|
|
|
class Place(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
links = generic.GenericRelation(Link)
|
2010-01-22 19:39:48 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2009-04-03 21:52:14 +02:00
|
|
|
return "Place: %s" % self.name
|
2010-01-22 19:39:48 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2010-01-22 19:39:48 +01:00
|
|
|
class Restaurant(Place):
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2010-01-22 19:39:48 +01:00
|
|
|
return "Restaurant: %s" % self.name
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2010-01-22 19:39:48 +01:00
|
|
|
class Address(models.Model):
|
|
|
|
street = models.CharField(max_length=80)
|
|
|
|
city = models.CharField(max_length=50)
|
|
|
|
state = models.CharField(max_length=2)
|
|
|
|
zipcode = models.CharField(max_length=5)
|
|
|
|
content_type = models.ForeignKey(ContentType)
|
|
|
|
object_id = models.PositiveIntegerField()
|
|
|
|
content_object = generic.GenericForeignKey()
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2010-01-22 19:39:48 +01:00
|
|
|
return '%s %s, %s %s' % (self.street, self.city, self.state, self.zipcode)
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2010-01-22 19:39:48 +01:00
|
|
|
class Person(models.Model):
|
|
|
|
account = models.IntegerField(primary_key=True)
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
addresses = generic.GenericRelation(Address)
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2010-01-22 19:39:48 +01:00
|
|
|
return self.name
|
2010-01-29 18:58:22 +01:00
|
|
|
|
|
|
|
class CharLink(models.Model):
|
|
|
|
content_type = models.ForeignKey(ContentType)
|
|
|
|
object_id = models.CharField(max_length=100)
|
|
|
|
content_object = generic.GenericForeignKey()
|
|
|
|
|
|
|
|
class TextLink(models.Model):
|
|
|
|
content_type = models.ForeignKey(ContentType)
|
|
|
|
object_id = models.TextField()
|
|
|
|
content_object = generic.GenericForeignKey()
|
|
|
|
|
|
|
|
class OddRelation1(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
clinks = generic.GenericRelation(CharLink)
|
|
|
|
|
|
|
|
class OddRelation2(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
tlinks = generic.GenericRelation(TextLink)
|
|
|
|
|
2010-02-10 20:21:52 +01:00
|
|
|
# models for test_q_object_or:
|
|
|
|
class Note(models.Model):
|
|
|
|
content_type = models.ForeignKey(ContentType)
|
|
|
|
object_id = models.PositiveIntegerField()
|
|
|
|
content_object = generic.GenericForeignKey()
|
|
|
|
note = models.TextField()
|
|
|
|
|
|
|
|
class Contact(models.Model):
|
|
|
|
notes = generic.GenericRelation(Note)
|
|
|
|
|
|
|
|
class Organization(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
contacts = models.ManyToManyField(Contact, related_name='organizations')
|
|
|
|
|