mirror of
https://github.com/django/django.git
synced 2024-12-28 03:55:50 +00:00
1a6da249c3
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13324 bcc190cf-cafb-0310-a4f2-bffc1f526a37
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
from datetime import datetime
|
|
|
|
from django.contrib.auth.models import User
|
|
from django.core import management
|
|
from django.db import models
|
|
|
|
|
|
# Forward declared intermediate model
|
|
class Membership(models.Model):
|
|
person = models.ForeignKey('Person')
|
|
group = models.ForeignKey('Group')
|
|
price = models.IntegerField(default=100)
|
|
|
|
def __unicode__(self):
|
|
return "%s is a member of %s" % (self.person.name, self.group.name)
|
|
|
|
# using custom id column to test ticket #11107
|
|
class UserMembership(models.Model):
|
|
id = models.AutoField(db_column='usermembership_id', primary_key=True)
|
|
user = models.ForeignKey(User)
|
|
group = models.ForeignKey('Group')
|
|
price = models.IntegerField(default=100)
|
|
|
|
def __unicode__(self):
|
|
return "%s is a user and member of %s" % (self.user.username, self.group.name)
|
|
|
|
class Person(models.Model):
|
|
name = models.CharField(max_length=128)
|
|
|
|
def __unicode__(self):
|
|
return self.name
|
|
|
|
class Group(models.Model):
|
|
name = models.CharField(max_length=128)
|
|
# Membership object defined as a class
|
|
members = models.ManyToManyField(Person, through=Membership)
|
|
user_members = models.ManyToManyField(User, through='UserMembership')
|
|
|
|
def __unicode__(self):
|
|
return self.name
|
|
|
|
# A set of models that use an non-abstract inherited model as the 'through' model.
|
|
class A(models.Model):
|
|
a_text = models.CharField(max_length=20)
|
|
|
|
class ThroughBase(models.Model):
|
|
a = models.ForeignKey(A)
|
|
b = models.ForeignKey('B')
|
|
|
|
class Through(ThroughBase):
|
|
extra = models.CharField(max_length=20)
|
|
|
|
class B(models.Model):
|
|
b_text = models.CharField(max_length=20)
|
|
a_list = models.ManyToManyField(A, through=Through)
|