Django model url keeps track your objects' urls and inserts dynamic links in content. Do not worry, that page has changed address. All the old links will continue to work.
Project description
Django-model-url helps you to show correctly links to all objects even if page`s url was changed.
Usage case
For example, you have news page on your web site. You add a lot of links to the news page from other pages. At some time you had to change url for the news page. This action lead to the problem: all old links are broken now. Of course, you can add redirect from old address to new. This can application solve problem more elegantly.
How it works?
Before you save content with hyperlink to your database django-model-url tries to replace it with something like this {@ myapp.models.MyModel id @}. Module will search for controller (view) that presents specified url. If controller will be found module calls it and looks for object in context that passed to template.
When ever such “macro-url” will appear in response it will be replaced with actual url.
Installation:
In settings.py:
Add 'modelurl' to your INSTALLED_APPS.
Add 'modelurl.middleware.ModelUrlMiddleware' to the end of MIDDLEWARE_CLASSES.
Configure the list of available models to be used by django-model-url
MODELURL_MODELS = [ { 'model': 'myapp.models.MyModel', }, ... ]
4. Configure the list of views that return objects of specified models. You must also specify the name of your context variable that represents your object
MODELURL_VIEWS = [ { 'view': 'myapp.views.get', 'context': 'object', }, ]
You can disable view if you don`t want to work with it:
MODELURL_VIEWS = [ { 'view': 'django.contrib.admin.site.root', 'disable': True, }, ]
Usage:
In your models:
You can check single url by hands before saving
from modelurl.utils import ReplaceByView class MyModel(models.Model): url = models.CharField(max_length=200) def save(self, *args, **kwargs): self.url = ReplaceByView().url(self.url) super(MyModel, self).save(*args, **kwargs)
You can check html before saving
from modelurl.utils import ReplaceByView class MyModel(models.Model): html = models.TextField() def save(self, *args, **kwargs): self.html = ReplaceByView().html(self.html) super(MyModel, self).save(*args, **kwargs)
You can use django-model-url together with django-trusted-html to make your html correct, pretty and safe.
Classifiers:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file redsolutioncms.django-model-url-0.1.0.tar.gz
.
File metadata
- Download URL: redsolutioncms.django-model-url-0.1.0.tar.gz
- Upload date:
- Size: 31.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c50ee9da966410c09124d1ef403c5f0f90fe08b52a1048a52c1c6f306e3286b9 |
|
MD5 | 3c9f428ed7984ccf1c2b63a106bed134 |
|
BLAKE2b-256 | cb906793cfa433cd346089e0cbb2138c90fec0031ef456b2ee13021ffe8d1afe |