Closed campegg closed 1 year ago
Hey,
For now you should be able to set slug = None
on your model to prevent inheriting it from MentionableMixin
. You will also need to override the resolve_from_url_kwargs
classmethod.
e.g.
# models.py
class Article(MentionableMixin, models.Model):
title = models.CharField(max_length=64)
content = models.TextField()
slug = None
def all_text(self) -> str:
return self.content
def get_absolute_url(self) -> str:
return reverse("article", args=[self.pk])
@classmethod
def resolve_from_url_kwargs(cls, article_id: int, **url_kwargs) -> "Article":
return Article.objects.get(pk=article_id)
# urls.py
urlpatterns = [
path(
"article/<int:article_id>/",
ArticleView.as_view(),
name="article",
kwargs={
"model_name": "sample_app.Article",
},
),
]
The slug field will likely be removed from MentionableMixin
in the next major release as it is no longer required (since 2.3.0
) and only used to provide the default resolve_from_url_kwargs
implementation.
Thanks @beatonma — much appreciated!
More of a question than an issue: I have a couple of legacy models that do not have a
slug
field, and am wondering if it is possible to enable mentions for them. I have tried defining aslug
in the model:… but it doesn't seem to work; I get:
Is there a way I can work around this?