Browse Source

Fix example of static counters for member count and subscriber count

Baptiste Jonglez 10 years ago
parent
commit
d5fd872e95
1 changed files with 19 additions and 14 deletions
  1. 19 14
      coin/isp_database/models.py

+ 19 - 14
coin/isp_database/models.py

@@ -36,6 +36,17 @@ class ISPInfo(SingleInstanceMixin, models.Model):
     The naming convention is different from Python/django so that it
     matches exactly the format (which uses CamelCase...)
     """
+    # These two properties can be overriden with static counters, see below.
+    @property
+    def memberCount(self):
+        """Number of members"""
+        return count_active_members()
+
+    @property
+    def subscriberCount(self):
+        """Number of subscribers to an internet access"""
+        return count_active_subscriptions()
+
     name = models.CharField(max_length=512,
                             help_text="The ISP's name")
     # Length required by the spec
@@ -70,10 +81,14 @@ class ISPInfo(SingleInstanceMixin, models.Model):
     longitude = models.FloatField(blank=True, null=True,
         help_text="Coordinates of the registered office (longitude)")
 
-    # Uncomment this if you want to manage these counters by hand.
-    #member_count = models.PositiveIntegerField(help_text="Number of members")
-    #subscriber_count = models.PositiveIntegerField(
-    #    help_text="Number of subscribers to an internet access")
+    # Uncomment this (and handle the necessary migrations) if you want to
+    # manage one of the counters by hand.  Otherwise, they are computed
+    # automatically, which is probably what you want.
+    #memberCount = models.PositiveIntegerField(help_text="Number of members",
+    #                                          default=0)
+    #subscriberCount = models.PositiveIntegerField(
+    #    help_text="Number of subscribers to an internet access",
+    #    default=0)
 
     # field outside of db-ffdn format:
     administrative_email = models.EmailField(
@@ -89,16 +104,6 @@ class ISPInfo(SingleInstanceMixin, models.Model):
         help_text="URL du serveur de listes de discussions/diffusion")
 
     @property
-    def memberCount(self):
-        """Number of members"""
-        return count_active_members()
-
-    @property
-    def subscriberCount(self):
-        """Number of subscribers to an internet access"""
-        return count_active_subscriptions()
-
-    @property
     def version(self):
         """Version of the API"""
         return API_VERSION