Take advantage of the Model inheritance provided by polymodel.PolyModel to
authorTodd Larsen <tlarsen@google.com>
Mon, 29 Sep 2008 15:46:42 +0000
changeset 208 e076aee6e90f
parent 207 8ecc2e4198cd
child 209 4ba836d74829
Take advantage of the Model inheritance provided by polymodel.PolyModel to have Club, School, Sponsor, and Organization actually inherit from the Group Model class, rather than being composed via ReferenceProperties. Patch by: Todd Larsen Review by: Pawel Solyga, Sverre Rabbelier, Augie Fackler Review URL: http://codereviews.googleopensourceprograms.com/606
app/soc/models/club.py
app/soc/models/group.py
app/soc/models/organization.py
app/soc/models/school.py
app/soc/models/sponsor.py
--- a/app/soc/models/club.py	Mon Sep 29 15:34:40 2008 +0000
+++ b/app/soc/models/club.py	Mon Sep 29 15:46:42 2008 +0000
@@ -27,7 +27,7 @@
 import soc.models.group
 
 
-class Club(base.ModelWithFieldAttributes):
+class Club(soc.models.group.Group):
   """Details specific to a Club.
 
   A Club is a generic type of Group that gathers Members into a community.
@@ -39,9 +39,5 @@
      relation is implemented as the 'members' back-reference Query of the
      Member model 'club' reference.
   """
+  pass
 
-  #: Required 1:1 relationship that ties Club details to the more generic
-  #: Group details.  The back-reference in the Group model is a Query
-  #: named 'club'.
-  group = db.ReferenceProperty(reference_class=soc.models.org.Group,
-                               required=True, collection_name="club")
--- a/app/soc/models/group.py	Mon Sep 29 15:34:40 2008 +0000
+++ b/app/soc/models/group.py	Mon Sep 29 15:46:42 2008 +0000
@@ -21,30 +21,18 @@
   '"Pawel Solyga" <pawel.solyga@gmail.com>',
 ]
 
+
 from google.appengine.ext import db
 
+import polymodel
+
 from django.utils.translation import ugettext_lazy
 
-from soc.models import base
 from soc.models import countries
 import soc.models.user
 
-class Group(base.ModelWithFieldAttributes):
+class Group(polymodel.PolyModel):
   """Common data fields for all groups.
-
-  A Group entity participates in the following relationships
-  implemented as a db.ReferenceProperty elsewhere in another db.Model:
-
-   school), club), sponsor), org)
-     a 1:1 relationship with each entity containing a more specific type of
-     Group.  These relationships are represented explicitly in the other
-     "group" models by a db.ReferenceProperty named 'group'.  The
-     collection_name argument to db.ReferenceProperty should be set to the
-     singular of the entity model name of the other "group" class.  The
-     above relationship names correspond, respectively to these Models:
-       School, Club, Sponsor, Organization
-     The relationships listed here are mutually exclusive.  For example,
-     a Group cannot be both a School and a Club at the same time.  
   """
 
   #: Required field storing name of the group.
@@ -126,4 +114,4 @@
   phone = db.PhoneNumberProperty(
       verbose_name=ugettext_lazy('Phone Number'))
   phone.help_text = ugettext_lazy(
-      'include complete international calling number with country code')
\ No newline at end of file
+      'include complete international calling number with country code')
--- a/app/soc/models/organization.py	Mon Sep 29 15:34:40 2008 +0000
+++ b/app/soc/models/organization.py	Mon Sep 29 15:46:42 2008 +0000
@@ -22,26 +22,19 @@
 
 from google.appengine.ext import db
 
-from soc.models import base
 from soc import models
 import soc.models.group
-import soc.models.administrator
 
-class Organization(base.ModelWithFieldAttributes):
+class Organization(soc.models.group.Group):
   """Organization details.
 
   A Organization entity participates in the following relationships implemented 
   as a db.ReferenceProperty elsewhere in another db.Model:
 
-   admins)  a many:1 relationship associating Administrators with
+   reviewers)  a many:1 relationship associating Reviewers with
      a specific Organization. This relation is implemented as the
-     'admins' back-reference Query of the Organization model 'org' reference.
-
+     'reviewers' back-reference Query of the Organization model 'org'
+     reference.
   """
+  pass
 
-  #: A 1:1 relationship associating a Organization with more generic
-  #: Group details and capabilities.  The back-reference in
-  #: the Group model is a Query named 'org'.
-  group = db.ReferenceProperty(reference_class=models.group.Group, 
-                               required=True, collection_name="org")
-                               
--- a/app/soc/models/school.py	Mon Sep 29 15:34:40 2008 +0000
+++ b/app/soc/models/school.py	Mon Sep 29 15:46:42 2008 +0000
@@ -27,7 +27,7 @@
 import soc.models.group
 
 
-class School(base.ModelWithFieldAttributes):
+class School(soc.models.group.Group):
   """Details specific to a School.
 
   A School is a specific type of Group that gathers Students together.
@@ -39,9 +39,5 @@
      belonging to) a School.  This relation is implemented as the 'students'
      back-reference Query of the Student model 'school' reference.
   """
+  pass
 
-  #: Required 1:1 relationship that ties School details to the more
-  #: generic Group details.  The back-reference in the Group model is a
-  #: Query named 'school'.
-  group = db.ReferenceProperty(reference_class=soc.models.group.Group,
-                               required=True, collection_name="school")
--- a/app/soc/models/sponsor.py	Mon Sep 29 15:34:40 2008 +0000
+++ b/app/soc/models/sponsor.py	Mon Sep 29 15:46:42 2008 +0000
@@ -23,16 +23,10 @@
 from google.appengine.ext import db
 
 from soc import models
-from soc.models import base
 import soc.models.group
 
 
-class Sponsor(base.ModelWithFieldAttributes):
+class Sponsor(soc.models.group.Group):
   """Sponsor details."""
+  pass
 
-  #: A 1:1 relationship associating a Sponsor with more generic
-  #: Group details and capabilities.  The back-reference in
-  #: the Group model is a Query named 'sponsor'.
-  group = db.ReferenceProperty(reference_class=models.group.Group, 
-                               required=True, collection_name="sponsor")
-                               
\ No newline at end of file