Package: django-meta-mixin
WarningVersion 0.2.1 is the last version ever ofdjango-meta-mixinAll the codebase, features and documentation has been moved tohttps://github.com/nephila/django-metaand it will be released indjango-meta1.0.django-meta1.0 is a drop-in replacement fordjango-meta-mixin: an emptydjango-meta-mixin0.3 package will be released together withdjango-meta-mixinto satisfy dependencies but all the following features and fixes will be released
indjango-meta.Conceptsdjango-meta-mixinprovides a mixin to handle metadata in your models.Actual data are evaluated at runtime pulling values from model attributes and
methods.To use it, defines a_metadataattribute as a dictionary of tag/value pairs;tagis the name of the metatag as used bymeta.htmltemplatevalueis a string that is evaluated in the following order:model method name called with the meta attribute as argumentmodel method name called with no argumentsmodel attribute name (evaluated at runtime)string literal (if none of the above exists)IfvalueisFalseor it is evaluated asFalseat runtime the tag is skipped.To use this mixin you must invokeas_meta()on the model instance
for example in the get_context_data().Requestas_meta()accepts therequestobject that is saved locally and is available to methods by
using theget_requestmethod.Public interfaceModelMeta.get_meta(request=None): returns the metadata attributes definition. Tipically these
are set in_metadataattribute in the model;ModelMeta.as_meta(request=None): returns the meta representation of the object suitable for
use in the template;ModelMeta.get_request(): returns therequestobject, if given as argument toas_meta;ModelMeta.get_author(): returns the author object for the current instance. Default
implementation does not return a valid object, thismustbe overidden in the application
according to what is an author in the application domain;ModelMeta.build_absolute_uri(url): create an absolute URL (i.e.: complete with protocol and
domain); this is generated from therequestobject, if given as argument toas_meta;InstallationFrom PyPi:pip install django-meta-mixinFrom github:pip install -e git+https://github.com/nephila/django-meta-mixin#egg=django-meta-mixinUsageAdd to installed apps along withdjango-meta:INSTALLED_APPS = [
    ...
    'meta',
    'meta_mixin',
]Configuredjango-metaaccording to documentation
(https://github.com/nephila/django-meta#configuration)Add meta information to your model:from django.db import models
from meta_mixin.models import ModelMeta

class MyModel(ModelMeta, models.Model):
    name = models.CharField(max_length=20)
    abstract = models.TextField()
    ...

    _metadata = {
        'title': 'name',
        'description': 'abstract',
        ...
    }Push metadata in the context usingas_metamethod:class MyView(DetailView):

    ...

    def get_context_data(self, **kwargs):
        context = super(MyView, self).get_context_data(self, **kwargs)
        context['meta'] = self.get_object().as_meta(self.request)
        return contextIncludemeta_mixin/meta.htmltemplate in your templates:{% load sekizai_tags %}

<html {% render_block 'html_extra' %}>
<head>
    {% include "meta_mixin/meta.html" %}
</head>
<body>
</body>
</html>NoteFor Google+ support you must add{% render_block 'html_extra' %}in your template to add object type definition. See relevant Google+ snippets documentation (https://developers.google.com/+/web/snippet/)ExampleLook at theexamplefolder for a sample implementation.Available propertiesdjango-meta-mixincurrently supports the following properties:Generic propertiestitle: object title,description: generic object description, used for SEO and as default for specific description,keywords: generic keywords for SEOlocale: advertised object locale (if any)image: image to display for objectobject_type: default object typepublished_time: date-time of publishingmodified_time: date-time of modificationexpiration_time: date-time of expirationurl: canonical object urlOpen Graph propertiesog_description: object description in Open Graphog_type: object type in Open Graphog_app_id: Facebook App IDog_profile_id: Author’s Facebook profileIDog_publisher: Facebook URL to publisher’s profileog_author_url: Facebook URL to author’s profiletag: object tagsTwitter Cards propertiestwitter_description: object description on Twitter card (currently 200 chars max)twitter_type: twitter card typetwitter_site: Website twitter accounttwitter_author: Author twitter accountGoogle+ Snippet propertiesgplus_description: object descriptiongplus_type: object type according to schema.org typesgplus_author: Author Google+ accountObject typesdjango-meta-mixinships with the following object types for each set of meta tags it supports:Generic / OpenGraphArticleWebsiteYou can override by definingMETA_OBJECT_TYPES/META_FB_TYPESnested
tuples in the project settings like:META_OBJECT_TYPES = (
    ('Article', _('Article')),
    ('Website', _('Website')),
)

META_FB_TYPES = (
    ('Article', _('Article')),
    ('Website', _('Website')),
)TwitterSummary CardSummary Card with Large ImageApp CardYou can override by definingMETA_TWITTER_TYPESnested
tuples in the project settings like:META_TWITTER_TYPES = (
    ('summary', _('Summary Card')),
    ('summary_large_image', _('Summary Card with Large Image')),
    ('app', _('App Card')),
)Google+ / Schema.orgArticleBlogWebPageWebSiteEventProductPlacePersonYou can override by definingMETA_GPLUS_TYPESnested
tuples in the project settings like:META_GPLUS_TYPES = (
    ('Article', _('Article')),
    ('Blog', _('Blog')),
    ('WebPage', _('Page')),
    ('WebSite', _('WebSite')),
    ('Event', _('Event')),
    ('Product', _('Product')),
    ('Place', _('Place')),
    ('Person', _('Person')),
)SettingsSome of the above properties can be set either in the model or via settings paramatersimage:META_DEFAULT_IMAGE(must be an absolute URL)object_type:META_SITE_TYPE(default: firstMETA_OBJECT_TYPES)og_type:META_FB_TYPE(default: firstMETA_FB_TYPES)og_app_id:META_FB_APPID(default: blank)og_profile_id:META_FB_PROFILE_ID(default: blank)og_publisher:META_FB_PUBLISHER(default: blank)og_author_url:META_FB_AUTHOR_URL(default: blank)twitter_type:META_TWITTER_TYPE(default: firstMETA_TWITTER_TYPES)twitter_site:META_TWITTER_SITE(default: blank)twitter_author:META_TWITTER_AUTHOR(default: blank)gplus_type:META_GPLUS_TYPE(default: firstMETA_GPLUS_TYPES)gplus_author:META_GPLUS_AUTHOR(default: blank)History0.2.2 (XXXX-XX-XX)Use autoescape off in template for Django 1.90.2.1 (2015-10-17)Add object types for facebook, twitter, google plusAdd translations0.2.0 (2015-10-03)Add support for using request in extracting metadataAdd one (optional) argument to class method call.Add support for editorconfigAdd get_meta method to allow customising metadataUse META_SITE_PROTOCOL when generating full URLExtend documentationClean up the codeUsebuild_absolute_urlinstead ofmake_full_url0.1.1 (2014-06-20)Addmake_full_urlmethod to retrieve complete object URL.0.1.0 (2014-04-19)First release on PyPI.