add redirects
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)
|
Loading…
Reference in New Issue