Django field for create snippet image for sharing in social networks.
Project description
The python package provides a django field for automatic generation of images for sharing in social networks.
django-snippet-image based on snippet-image package.
Installation
` pip3 install django-snippet-image `
Example
Use SnippetImageField:
from django.db.models import (
Model,
CharField,
ImageField,
)
from django_snippet_image import SnippetImageField
class Statuses:
DRAFT = 'draft'
PUBLISH = 'publish'
CHOICES = (
(DRAFT, 'Draft'),
(PUBLISH, 'Publish'),
)
class ExampleModel(Model):
text = CharField(
max_length=200,
verbose_name='Text for snippet image',
)
background = ImageField(
verbose_name='Background for snippet image',
blank=True,
null=True,
)
snippet_image_field = SnippetImageField(
verbose_name='Example snippet image field',
null=True,
)
status = CharField(
max_length=20,
choices=Statuses.CHOICES,
)
# Methods for collect data for snippet image.
def get_snippet_image_text(self, snippet_type):
return self.text if snippet_type == 'default' and self.text else ''
def get_snippet_image_background(self, snippet_type):
if snippet_type == 'default' and self.background:
return self.background.path
def snippet_image_should_be_created(self):
return self.status == Statuses.PUBLISH
class Meta:
verbose_name = 'example object'
verbose_name_plural = 'example objects'
And use in template:
<meta property="og:image" content="{{ instance.snippet_image_field.url }}" />
Read more on home page.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-snippet-image-0.1.3.tar.gz
.
File metadata
- Download URL: django-snippet-image-0.1.3.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.15 CPython/3.7.3 Linux/5.0.0-15-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b57bb861318a76814b3ddb4fed5df002f3debe01c5df81356ae1d778ef9fc84c |
|
MD5 | 9e22d063360f97f614b8b1d3784c3e9f |
|
BLAKE2b-256 | 0a100c2eaef676e90b31950ba1dd5e6dfb441577dec36f3a59308a610bcdd62a |
File details
Details for the file django_snippet_image-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: django_snippet_image-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.15 CPython/3.7.3 Linux/5.0.0-15-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73e03935f5d9b1ba0d29b9ab57a22162573c4380370b8abbdf276b265fbc75a2 |
|
MD5 | ebc8e5f23dc784c02836d1a3fda06ee7 |
|
BLAKE2b-256 | cc83e4c32ee55ed10ed128222cd9bd3e19280b46f6e86c13e4c299e3a2dfda20 |