add redirects
This commit is contained in:
parent
8c4275d7c6
commit
9dda2c1f62
|
@ -0,0 +1,6 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
from .models import Redirect
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
admin.site.register(Redirect)
|
|
@ -0,0 +1,6 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class RedirectsConfig(AppConfig):
|
||||||
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
|
name = "shiftregister.redirects"
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Generated by Django 4.0.4 on 2022-05-26 13:04
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = []
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Redirect",
|
||||||
|
fields=[
|
||||||
|
("slug", models.SlugField(primary_key=True, serialize=False)),
|
||||||
|
("target", models.URLField()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,11 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class Redirect(models.Model):
|
||||||
|
slug = models.SlugField(primary_key=True)
|
||||||
|
target = models.URLField()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.slug} => {self.target}"
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
|
@ -0,0 +1,8 @@
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
app_name = "redirects"
|
||||||
|
urlpatterns = [
|
||||||
|
path("<slug:slug>", views.redir, name="redir"),
|
||||||
|
]
|
|
@ -0,0 +1,9 @@
|
||||||
|
from django.shortcuts import redirect, get_object_or_404
|
||||||
|
from .models import Redirect
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
|
def redir(request, slug):
|
||||||
|
obj = get_object_or_404(Redirect, pk=slug)
|
||||||
|
return redirect(obj.target)
|
|
@ -45,6 +45,7 @@ INSTALLED_APPS = [
|
||||||
"shiftregister.pages.apps.PagesConfig",
|
"shiftregister.pages.apps.PagesConfig",
|
||||||
"shiftregister.metrics.apps.MetricsConfig",
|
"shiftregister.metrics.apps.MetricsConfig",
|
||||||
"shiftregister.signage.apps.SignageConfig",
|
"shiftregister.signage.apps.SignageConfig",
|
||||||
|
"shiftregister.redirects.apps.RedirectsConfig",
|
||||||
"django.contrib.admin",
|
"django.contrib.admin",
|
||||||
"django.contrib.auth",
|
"django.contrib.auth",
|
||||||
"django.contrib.contenttypes",
|
"django.contrib.contenttypes",
|
||||||
|
|
|
@ -21,6 +21,7 @@ urlpatterns = [
|
||||||
path("team/", include("shiftregister.team.urls")),
|
path("team/", include("shiftregister.team.urls")),
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
path("p/", include("shiftregister.pages.urls")),
|
path("p/", include("shiftregister.pages.urls")),
|
||||||
|
path("r/", include("shiftregister.redirects.urls")),
|
||||||
path("metrics/", include("shiftregister.metrics.urls")),
|
path("metrics/", include("shiftregister.metrics.urls")),
|
||||||
path("", include("shiftregister.signage.urls")),
|
path("", include("shiftregister.signage.urls")),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue