-
Notifications
You must be signed in to change notification settings - Fork 2
Guide_Using MentionableMixin
Include MentionableMixin
in the model(s) you want to support webmention functionality.
Any models that include the mixin must implement the get_content_html
and get_absolute_url
methods:
# models.py
from mentions.models.mixins import MentionableMixin
class Article(MentionableMixin, models.Model):
content = models.TextField()
def get_content_html(self) -> str:
return self.content
def get_absolute_url(self) -> str:
return reverse("article", args=[self.id])
When you save
your model instance, django-wm
will submit a webmention to any linked websites that are capable of accepting them.
Add urlpatterns
metadata for any views that represent a MentionableMixin
model instance. The mentions_path
helper is the easiest way to do this - see here for details and further configuration options.
# your_app/urls.py
from mentions.helpers import mentions_path
urlpatterns = [
mentions_path(
"article/<int:article_id>/",
ArticleView.as_view(),
model_class=Article,
model_filter_map={
"article_id": "id",
},
name="article",
),
]
This allows us to associate a received webmention to your model instance. In this example, a webmention that targets https://yoursite.com/article/4/
will generate the query Article.objects.get(id=4)
, and the resulting Webmention instance will have a GenericForeignKey
linking to that Article
instance.