Advertisement
Guest User

Untitled

a guest
May 31st, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. def RegisterView(request):
  2. if request.method == 'POST':
  3. response_data = {}
  4. domain = request.POST.get('domain')
  5. schema = request.POST.get('schema')
  6. name = request.POST.get('name')
  7. description = request.POST.get('description')
  8.  
  9. client=Client()
  10. Client.domain_url=domain
  11. Client.schema_name=schema
  12. Client.name=name
  13. Client.description=description
  14. Client.save()
  15.  
  16. from customers.models import Client
  17.  
  18. class Client(TenantMixin):
  19. name = models.CharField(max_length=100)
  20. description = models.TextField(max_length=200)
  21. created_on = models.DateField(auto_now_add=True)
  22.  
  23. class TenantMixin(models.Model):
  24. """
  25. All tenant models must inherit this class.
  26. """
  27.  
  28. auto_drop_schema = False
  29. """
  30. USE THIS WITH CAUTION!
  31. Set this flag to true on a parent class if you want the schema to be
  32. automatically deleted if the tenant row gets deleted.
  33. """
  34.  
  35. auto_create_schema = True
  36. """
  37. Set this flag to false on a parent class if you don't want the schema
  38. to be automatically created upon save.
  39. """
  40.  
  41. domain_url = models.CharField(max_length=128, unique=True)
  42. schema_name = models.CharField(max_length=63, unique=True,
  43. validators=[_check_schema_name])
  44.  
  45. class Meta:
  46. abstract = True
  47.  
  48. def save(self, verbosity=1, *args, **kwargs):
  49. is_new = self.pk is None
  50.  
  51. if is_new and connection.schema_name != get_public_schema_name():
  52. raise Exception("Can't create tenant outside the public schema. "
  53. "Current schema is %s." % connection.schema_name)
  54. elif not is_new and connection.schema_name not in (self.schema_name, get_public_schema_name()):
  55. raise Exception("Can't update tenant outside it's own schema or "
  56. "the public schema. Current schema is %s."
  57. % connection.schema_name)
  58.  
  59. super(TenantMixin, self).save(*args, **kwargs)
  60.  
  61. if is_new and self.auto_create_schema:
  62. try:
  63. self.create_schema(check_if_exists=True, verbosity=verbosity)
  64. except:
  65. # We failed creating the tenant, delete what we created and
  66. # re-raise the exception
  67. self.delete(force_drop=True)
  68. raise
  69. else:
  70. post_schema_sync.send(sender=TenantMixin, tenant=self)
  71.  
  72. save() missing 1 required positional argument: 'self'
  73.  
  74. Traceback:
  75.  
  76. File "/home/sayantan/Desktop/djangowork/my_env/lib/python3.4/site- packages/django/core/handlers/base.py" in get_response
  77. 149. response = self.process_exception_by_middleware(e, request)
  78.  
  79. File "/home/sayantan/Desktop/djangowork/my_env/lib/python3.4/site- packages/django/core/handlers/base.py" in get_response
  80. 147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
  81.  
  82. File "/home/sayantan/Desktop/djangowork/invoice/invoice/views.py" in RegisterView
  83. 55. Client.save()
  84.  
  85. Exception Type: TypeError at /register/
  86. Exception Value: save() missing 1 required positional argument: 'self'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement