django-opengraph-meta (0.1.2b1)
Installation
pip install --index-url django-opengraph-meta
About this package
Django models for OpenGraph based metadata; Server-side metadata generation
django-opengraph-meta
This package contains models, which implements containing and generating extra part of the page's meta information. It is introduced by the OpenGraph and TwitterCard entities
Package includes
Basic models:
- OpenGraph: Webpage
- OpenGraph: Article
- OpenGraph: Book
- OpenGraph: Profile
- OpenGraph: Music.Song
- OpenGraph: Music.Album
- OpenGraph: Music.Playlist
- OpenGraph: Music.Radio Station
- OpenGraph: Video.Movie
- OpenGraph: Video.Episode
- OpenGraph: Video.TV Show
- OpenGraph: Video.Other
Extra models:
TwitterCard models:
Package struct
-
models
- OGWebPage
- OGArticlePage
- OGBookPage
- OGProfilePage
- OGMusicSongPage
- OGMusicAlbumPage
- OGMusicPlaylistPage
- OGMusicRadioStationPage
- OGVideoMoviePage
- OGVideoEpisodePage
- OGVideoTVShowPage
- OGVideoOtherPage
-
properties
-
other
- OGBusinessPage
- OGProductPage
-
properties
-
social_media
- TwitterCard (source)
- TwitterCardApp
- TwitterCardSummary
- TwitterCardSummaryLargeImage
- TwitterCardPlayer
-
properties
Concepts
Database app_label
If
OPENGRAPH_META_APP_LABEL
would be found in django.conf.settings it will be used as prefix each db model name, exclude TwitterCards models, which useTWITTER_CARD_META_APP_LABEL
Universal page attributes:
Class methods:
og_name
(cls
)- Returns the OpenGraph scope name, which was set at the class initialization
og_properties
(cls
)- Returns the OpenGraph scope properties, which was set at the class initialization
Methods:
og_metadata
(self
)- Returns the
Generator[Tuple[str, str]]
with collected meta information. Empty fields will not be included to that selection.
- Returns the
og_name
(self
)- Return
Generator[str]
(wrapped metadata), which present asIterable
HTML DOM based meta tags
- Return
Universal subpage attributes
Class OGSubpage (source) is a parent of each page class, excluding the OGWebPage. It determines ForeignKey field
page
, which links to OGWebPage object associated for present data. It proxied two properties of thepage
url
title
, to the main OGSubpage scope
Universal music attributes
Arguments
*args
and**kwargs
will be transfer to selected object instance constructor without any modification.
Class methods:
create_song
(cls
,*args
,**kwargs
): Returns new OGMusicSongPage instancecreate_album
(cls
,*args
,**kwargs
): Returns new OGMusicAlbumPage instancecreate_playlist
(cls
,*args
,**kwargs
): Returns new OGMusicPlaylistPage instancecreate_radio_station
(cls
,*args
,**kwargs
): Returns new OGMusicRadioStationPage instance
Database fields:
- ForeignKey
audio
: The audio file (source) associated with the page
Universal video attributes
Arguments
*args
and**kwargs
will be transfer to selected object instance constructor without any modification.
Class methods:
create_movie
(cls
,*args
,**kwargs
): Returns new OGVideoMoviePage instancecreate_episode
(cls
,*args
,**kwargs
): Returns new OGVideoEpisodePage instancecreate_tv_show
(cls
,*args
,**kwargs
): Returns new OGVideoTVShowPage instancecreate_other
(cls
,*args
,**kwargs
): Returns new OGVideoOtherPage instance
Database fields:
- ForeignKey
video
: The video file (source) associated with the page- URLField
url
: Contains video's url. (og:video
) - CharField
type
: Contains MIME type of the video. (og:video:type
) - URLField
secure_url
: Contains video's alternate url to use if the webpage requires HTTPS. (og:video:secure_url
) - PositiveSmallIntegerField
width
: Contains width of the video. (og:video:width
) - PositiveSmallIntegerField
height
: Contains height of the video. (og:video:height
)
- URLField
- PositiveSmallIntegerField
duration
: Duration of the video in seconds (video:duration
) - DateField
release_date
: Contains date of video release. Metadata represented asYYYY-MM-DD
(ISO 8601) string (video:release_date
) - ManyToManyField
actors
: Array of the actor's extended profiles, metadata represent as URL of attached profile and:role
parameter, if it is existed (video:actor
) - ManyToManyField
directors
: Array of the director's profiles, metadata represent as URL of attached profile (video:director
) - ManyToManyField
writers
: Array of the writer's profiles, metadata represent as URL of attached profile (video:writer
) - ForeignKey
series
: Contains link to OGVideoTVShowPage, metadata represent as URL of attached video. It uses only in OGVideoEpisodePage (video:series
)
Universal TwitterCard attributes
Class methods:
create_player
(cls
,*args
,**kwargs
): Returns new TwitterCardPlayer instancecreate_summary
(cls
,*args
,**kwargs
): Returns new TwitterCardSummary instancecreate_summary_large_image
(cls
,*args
,**kwargs
): Returns new TwitterCardSummaryLargeImage instancecreate_app
(cls
,*args
,**kwargs
): Returns new TwitterCardApp instance
Database fields:
- PositiveSmallIntegerField
card
: Value of the card's type, it will be converted to string in the process of metadata generation (twitter:card
) - ForeignKey
site
: TwitterCardSite (source) profile info associated with the page
Product classification
Model OGProductPage uses predefined values of the Google's taxonomy classification. It is a big document (~5.5k lines) with the deep enclosing and inheritance of the categories. So, that module support each element of the taxonomy, but not used all of them by default. Project setting's variable
OPENGRAPH_PRODUCT_TAXONOMY_DEPTH
defines level of the enclosing, which will be presented by root classCategories
(source) (2 by default). It means, that second enclosing of the category (for example:OGProductPage.Categories.AnimalsAndPetSupplies.LiveAnimals
) cannot contain any subcategory and would be final. IfOPENGRAPH_PRODUCT_TAXONOMY_DEPTH
is equal0
, it is means, that there is no any enclosing limits.Note: List of the categories, which are contained into the current
Taxonomy
instance (source) can be got by the method of that instancecategories(self)
You can use the setting's variable
OPENGRAPH_PRODUCT_TAXONOMY_BASE
for the defining the root category of your current project. For example, if your project is used for the cloth sale, it can be sensible to set theOPENGRAPH_PRODUCT_TAXONOMY_BASE = 'ApparelAndAccessories.Clothing'
. It excludes the non-contextual values from the choices of OGProductPage.category.Setting's variable
OPENGRAPH_PRODUCT_TAXONOMY_FILEPATH
can be used for the linking of custom taxonomy file, instead of builtin taxonomy.json, for the categories tree buildBoolean setting's variable
OPENGRAPH_PRODUCT_TAXONOMY_FULLNAME
(False
by default) determines the name of category entity, which would be present at thechoices
property.fullname
reflects the tree, in contrast of thename
Currency code
Model
OGPrice
(source) uses a part of logic the Product classification in the currency defines. It has support two variables:OPENGRAPH_PRODUCT_CURRENCY_FULLNAME
andOPENGRAPH_PRODUCT_CURRENCY_FILEPATH
with same logic. So if you want to limit list of currencies in your project, creation project-specificcurrency.json
is a simple way to do itSee:
See also:
- OpenGraph basic metadata
- OpenGraph optional metadata
- OpenGraph arrays
- OpenGraph business reference
- OpenGraph Facebook specific product
- TwitterCard description
Basic models
OGWebPage
Database fields:
- URLField
url
: Contains page's url. (og:url
) - PositiveSmallIntegerField
type
: Contains page's opengraph type (see) (og:type
) - CharField
title
: Contains page's title (og:type
) - CharField
description
: Contains page's description (og:description
) - ManyToManyField
images
: Array of the images (source) associated with the page (og:image
)- URLField
url
: Contains image's url. (og:image
) - CharField
type
: Contains MIME type of the image. (og:image:type
) - URLField
secure_url
: Contains image's alternate url to use if the webpage requires HTTPS. (og:image:secure_url
) - PositiveSmallIntegerField
width
: Contains width of the image. (og:image:width
) - PositiveSmallIntegerField
height
: Contains height of the image. (og:image:height
) - CharField
alt
: Contains description of what is in the image. (og:image:alt
)
- URLField
Properties
locale
: Returns result of to_locale(get_language()) (og:locale
)locales_alt
: Returns nothing, but set the interface to returningIterable
object. User may redefine this property on inheritance (og:locale:alternate
)determiner
: Returns nothing, but set the interface to returningstr
. (og:determiner
)site_name
: Returns value ofOPENGRAPH_SITE_NAME
(None
if not present) which can be set in main project settings file
OGArticlePage
Database fields:
- CharField
section
: Contains the global category value of the article (article:section
) - DateTimeField
published_time
: Contains date and time of article's publication. Metadata represented asYYYY-MM-DDThh:mm
(ISO 8601) string (article:published_time
) - DateTimeField
modified_time
: Contains date and time of last article's modification. Metadata represented asYYYY-MM-DDThh:mm
(ISO 8601) string (article:modified_time
) - DateTimeField
expiration_time
: Contains date and time of article's expiration. Metadata represented asYYYY-MM-DDThh:mm
(ISO 8601) string (article:expiration_time
) - ManyToManyField
authors
: Contains an array of the author's profiles- URLField
url
: Contains author's page url. (article:author
)
- URLField
- ManyToManyField
tags
: Contains an array of the tags associated with this object (article:tag
)
OGBookPage
Database fields:
- CharField
isbn
: Contains 13-Digit ISBN (book:isbn
) - DateField
release_date
: Contains date of book release. Metadata represented asYYYY-MM-DD
(ISO 8601) string (book:release_date
) - ManyToManyField
authors
: Array of the author's profiles- URLField
url
: Contains author's page url. (book:author
)
- URLField
- ManyToManyField
tags
: Array of the tags associated with this object (book:tag
)
OGProfilePage
Database fields:
- BooleanField
is_male
: Is used for handling bygender
property - CharField
first_name
: First name of described person (profile:first_name
) - CharField
last_name
: Last name of described person (profile:last_name
) - CharField
username
: Username of described person (profile:username
)
Properties
gender
: ReturnsNone
if fieldis_male
is null. Returns'male'
ifis_male
is true,'female'
in else (profile:gender
)
OGMusicSongPage
- OpenGraph documentation
- Source file
- Universal page attributes
- Universal subpage attributes
- Universal music attributes
Database fields:
- PositiveSmallIntegerField
disc
: Album disc number (music:album:disc
) - PositiveSmallIntegerField
track
: Track number at the album (music:album:track
) - ForeignKey
album
: Contains link to the OGMusicAlbumPage- URLField
url
: Contains album's page url. (music:album
)
- URLField
- ManyToManyField
musicians
: Array of the musician's profiles- URLField
url
: Contains musician's page url. (music:musician
)
- URLField
- PositiveSmallIntegerField
duration
: Duration of the song in seconds (music:duration
)
OGMusicAlbumPage
- OpenGraph documentation
- Source file
- Universal page attributes
- Universal subpage attributes
- Universal music attributes
Database fields:
- DateField
release_date
: Contains date of object release Metadata represented asYYYY-MM-DD
(ISO 8601) string (music:release_date
) - ManyToManyField
creators
: Array of the musician's profiles, metadata represent as URL of attached profile (music:musician
)- URLField
url
: Contains musician's page url. (music:musician
)
- URLField
- ManyToManyField
songs
: Array of the songs- URLField
url
: Contains page url of the song. (music:song
) - PositiveSmallIntegerField
disc
: Contains disc number of the song's album. (music:song:disc
) - PositiveSmallIntegerField
track
: Contains track number of the song in album. (music:song:track
)
- URLField
OGMusicPlaylistPage
- OpenGraph documentation
- Source file
- Universal page attributes
- Universal subpage attributes
- Universal music attributes
Database fields:
- ManyToManyField
creators
: Array of the creator's profiles- URLField
url
: Contains creator's page url. (music:creator
)
- URLField
- ManyToManyField
songs
: Array of the songs- URLField
url
: Contains page url of the song. (music:song
) - PositiveSmallIntegerField
disc
: Contains disc number of the song's album. (music:song:disc
) - PositiveSmallIntegerField
track
: Contains track number of the song in album. (music:song:track
)
- URLField
OGMusicRadioStationPage
- OpenGraph documentation
- Source file
- Universal page attributes
- Universal subpage attributes
- Universal music attributes
Database fields:
- ManyToManyField
creators
: Array of the creator's profiles- URLField
url
: Contains creator's page url. (music:creator
)
- URLField
OGVideoMoviePage
- OpenGraph documentation
- Source file
- Universal page attributes
- Universal subpage attributes
- Universal video attributes
OGVideoEpisodePage
- OpenGraph documentation
- Source file
- Universal page attributes
- Universal subpage attributes
- Universal video attributes
OGVideoTVShowPage
- OpenGraph documentation
- Source file
- Universal page attributes
- Universal subpage attributes
- Universal video attributes
OGVideoOtherPage
- OpenGraph documentation
- Source file
- Universal page attributes
- Universal subpage attributes
- Universal video attributes
Extra models
OGBusinessPage
Database fields:
- ForeignKey
contact_data
: Contains link to the OGContactData property (source), which can contain:- CharField
street_addres
: Contains physical address of the object (business:contact_data:stree_addres
) - CharField
locality
: Contains locality of the object (business:contact_data:locality
) - CharField
region
: Contains region of the object (business:contact_data:region
) - CharField
postal_code
: Contains postal_code of the object (business:contact_data:postal_code
) - CharField
country_name
: Contains county name of the object (business:contact_data:country_name
) - EmailField
email
: Contains email of the object (business:contact_data:email
) - CharField
phone_number
: Contains phone number of the object (business:contact_data:phone_number
) - CharField
fax_number
: Contains fax number of the object (business:contact_data:fax_number
) - URLField
website
: Contains url to website of the object (business:contact_data:website
)
- CharField
- ForeignKey
place
: Contains link to the OGContactData property (source), which can contain:- DecimalField
latitude
: Geographic latitude (business:place:latitude
) - DecimalField
longitude
: Geographic longitude (business:place:longitude
)
- DecimalField
OGProductPage
Database fields:
- ForeignKey
price
: Contains link to the OGGlobalPrice property (source), which can contain:- DecimalField
amount
: Price of the product (og:price:amount
) - PositiveSmallIntegerField
currency
: Contains code of the currency (og:price:currency
)
- DecimalField
- PositiveSmallIntegerField
availability
: Value of the product's availability. (product:availability
) - PositiveSmallIntegerField
condition
: Value of the product's condition. (product:condition
) - PositiveSmallIntegerField
material
: Value of the product's material. (material
) - CharField
brand
: Brand name of the product (product:brand
) - PositiveIntegerField
category
: Category id from the Google's taxonomy classification (product:category
) - CharField
gtin
: GTIN of the product (product:gtin
) - BooleanField
is_male
: Is used for handling bygender
property
Properties
gender
: Returnsunisex
if fieldis_male
is null. Returns'male'
ifis_male
is true,'female'
in else (product:gender
)
TwitterCard models
TwitterCardApp
Database fields:
- ManyToManyField
apps
: Array of TwitterCardAppInfo (source). User responsible that any of theapp.type
would be contained once in that field- PositiveSmallIntegerField
type
: Value of the app's device, it would be used for[postfix]
of that metamodel - CharField
type
: Application name (twitter:app:name:[postfix]
) - CharField
id
: Application marketplace id (twitter:app:id:[postfix]
) - CharField
url
: Application marketplace id (twitter:app:url:[postfix]
)
- PositiveSmallIntegerField
TwitterCardSummary
Database fields:
- ForeignKey
image
: TwitterCardImage (source) image associated with the page - ForeignKey
creator
: TwitterCardCreator (source) profile info associated with the page
TwitterCardSummaryLargeImage
Database fields:
- ForeignKey
image
: TwitterCardImage (source) image associated with the page - ForeignKey
creator
: TwitterCardCreator (source) profile info associated with the page
TwitterCardPlayer
Database fields:
- ForeignKey
image
: TwitterCardImage (source) image associated with the page - ForeignKey
player
: TwitterCardPlayer (source) iframe associated with the page- URLField
url
: Contains iframe url. (twitter:player
) - URLField
stream
: Contains raw video url. (twitter:player:stream
) - PositiveSmallIntegerField
width
: Width of the video iframe. (twitter:player:width
) - PositiveSmallIntegerField
height
: Height of the video iframe. (twitter:player:height
)
- URLField