Browse Source

Fix the admin for VPNSubscription

It's still not perfect, see comment in the code.
Baptiste Jonglez 11 years ago
parent
commit
954984f460
1 changed files with 9 additions and 5 deletions
  1. 9 5
      coin/vpn/models.py

+ 9 - 5
coin/vpn/models.py

@@ -45,11 +45,15 @@ class VPNSubscription(CoinLdapSyncModel):
     administrative_subscription = models.OneToOneField(
         'offers.OfferSubscription',
         related_name='openvpn_ldap',
-        limit_choices_to={
-            # Only consider VPN subscription...
-            'offer__backend': 'openvpn_ldap',
-            # ...with no VPNSubscription object associated yet
-            'openvpn_ldap': None},
+        # Only consider VPN subscriptions.
+        # TODO: also filter out subscriptions that already have a OneToOne
+        # relation.  Simply adding "'openvpn_ldap': None" to the
+        # dictionary does not work well, as it will also remove ourselves
+        # from the list when editing the object in the admin.  Using a Q()
+        # query does not solve the problem, as there is no way to
+        # reference ourselves.  The proper solution would be to create a
+        # custom form.
+        limit_choices_to={'offer__backend': 'openvpn_ldap'},
         validators=[validate_backend_type])
     # TODO: do some access control to prevent the user from changing this field
     activated = models.BooleanField(default=False)