-
Notifications
You must be signed in to change notification settings - Fork 2
Models and Mixins
django-wm
uses a number of models to keep track of webmention-related data. This page lists the main ones that you are likely to interact with along with some of their more useful attributes.
A simple representation of an h-card. Used to store basic information, if available, about the author of a Webmention.
Represents a webmention that you sent elsewhere.
A 'fake' webmention which you can create manually. You might want to do this if you see a link to your content on a site that does not support webmentions. May be associated with an HCard instance.
Represents a webmention that you received from elsewhere. May be associated with an HCard instance.
This should be inherited by any model that you want to be capable of sending webmentions. Your model must override the get_content_html
and get_absolute_url
methods. Depending on your urlpatterns configuration, you may also need to override the @classmethod
resolve_from_url_kwargs
.
# Example implementation
class Article(MentionableMixin, models.Model):
author = models.CharField(max_length=64)
title = models.CharField(max_length=64)
content = models.TextField()
slug = None # Optionally remove `slug` field inherited from `MentionableMixin`
def get_content_html(self) -> str:
"""Return the HTML-formatted content of your model.
Any links found in this content will be treated as potential
targets for submitting webmentions."""
return self.content
def get_absolute_url(self) -> str:
"""Return the URL path which represents"""
return reverse("article", args=[self.pk])
@classmethod
def resolve_from_url_kwargs(cls, article_id: int, **url_kwargs) -> "Article":
"""This is not required if you use `mentions_path` in `urlpatterns`.
Use URL path parameters to resolve the correct model instance.
This method will receive the arguments defined in `urlpatterns`.
"""
return Article.objects.get(pk=article_id)