1
0
mirror of https://github.com/django/django.git synced 2025-06-30 07:49:19 +00:00

29 lines
1.0 KiB
Python

from django.db import models
from django.utils.translation import ugettext_lazy as _
class SiteManager(models.Manager):
def get_current(self):
from django.conf import settings
try:
sid = settings.SITE_ID
except AttributeError:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured("You're using the Django \"sites framework\" without having set the SITE_ID setting. Create a site in your database and set the SITE_ID setting to fix this error.")
return self.get(pk=sid)
class Site(models.Model):
domain = models.CharField(_('domain name'), maxlength=100)
name = models.CharField(_('display name'), maxlength=50)
objects = SiteManager()
class Meta:
db_table = 'django_site'
verbose_name = _('site')
verbose_name_plural = _('sites')
ordering = ('domain',)
class Admin:
list_display = ('domain', 'name')
search_fields = ('domain', 'name')
def __unicode__(self):
return self.domain