def update_site(sender, **kwargs):
"""
Update `Site` object matching `SITE_ID` setting with `SITE_DOMAIN` and
`SITE_PORT` settings.
"""
Site = apps.get_model('sites', 'Site')
domain = settings.SITE_DOMAIN
if settings.SITE_PORT:
domain += ':%s' % settings.SITE_PORT
Site.objects.update_or_create(
pk=settings.SITE_ID,
defaults=dict(
domain=domain,
name=settings.SITE_NAME))
# We set an explicit pk instead of relying on auto-incrementation,
# so we need to reset the database sequence.
sequence_sql = connection.ops.sequence_reset_sql(no_style(), [Site])
if sequence_sql:
cursor = connection.cursor()
for command in sequence_sql:
cursor.execute(command)
评论列表
文章目录