Skip to content

Commit

Permalink
Added reverse for tenants. #87
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartlomiej Mika committed Jul 5, 2016
1 parent 04139c5 commit e57507d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions django_tenants/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.conf import settings
from django.db import models, connection, transaction
from django.core.management import call_command
from django.contrib.sites.shortcuts import get_current_site
from django.core.urlresolvers import resolve, reverse

from .postgresql_backend.base import _check_schema_name
from .signals import post_schema_sync, schema_needs_to_be_sync
Expand Down Expand Up @@ -145,6 +147,16 @@ def get_primary_domain(self):
except get_tenant_domain_model().DoesNotExist:
return None

def reverse(self, request, view_name):
"""
Returns the URL of this tenant.
"""
url = 'https://' if request.is_secure() else 'http://'
url += str(self.schema_name) + '.'
url += get_current_site(request).domain
url += reverse(view_name)
return url


class DomainMixin(models.Model):
"""
Expand Down
9 changes: 9 additions & 0 deletions dts_test_project/customers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ class Client(TenantMixin):
description = models.TextField(max_length=200, blank=True, null=True)
created_on = models.DateField(auto_now_add=True)

def reverse(self, request, view_name):
"""
If you have different implementation of reserve from what the
Django-Tenants library uses (A.k.a. Sites Framework) then you can write
your own override here.
"""
# Write your own custom code else use existing code.
return super( Client, self ).reverse(request, view_name)


class Domain(DomainMixin):
pass

0 comments on commit e57507d

Please sign in to comment.