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:
Metadata
Release files for redsolutioncms.django-model-url 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| redsolutioncms.django-model-url-0.1.0.tar.gz | 31.8 kB | Without provenance | Details |
Release files / redsolutioncms.django-model-url-0.1.0.tar.gz
| Download URL | redsolutioncms.django-model-url-0.1.0.tar.gz |
|---|---|
| Size | 31.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c50ee9da966410c09124d1ef403c5f0f90fe08b52a1048a52c1c6f306e3286b9
|
|
BLAKE2b-256 checksum How to use checksums |
cb906793cfa433cd346089e0cbb2138c90fec0031ef456b2ee13021ffe8d1afe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for redsolutioncms.django-model-url 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.