X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/4bb5959d246fa0528b83fc3e21f9e5782ec34236..4a6513cd9ed9d66351b8973d3455204aad684fb5:/src/catalogue/wikidata.py?ds=sidebyside diff --git a/src/catalogue/wikidata.py b/src/catalogue/wikidata.py index 4e63c095..4fc8bbd8 100644 --- a/src/catalogue/wikidata.py +++ b/src/catalogue/wikidata.py @@ -1,6 +1,10 @@ +# This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# from datetime import date from django.db import models from django.db.models.signals import m2m_changed +from django.utils.html import format_html from django.utils.translation import gettext_lazy as _ from django.dispatch import receiver from wikidata.client import Client @@ -10,9 +14,7 @@ from wikidata.datavalue import DatavalueError class WikidataMixin(models.Model): wikidata = models.CharField( max_length=255, - null=True, blank=True, - unique=True, help_text=_('If you have a Wikidata ID, like "Q1337", enter it and save.'), ) @@ -80,6 +82,17 @@ class WikidataMixin(models.Model): wdvalue = wdvalue.label.get("pl", str(wdvalue.label)) setattr(self, attname, wdvalue) + def wikidata_link(self): + if self.wikidata: + return format_html( + '{wd}', + wd=self.wikidata, + ) + else: + return "" + + wikidata_link.admin_order_field = "wikidata" + class WikidataAdminMixin: def save_related(self, request, form, formsets, change):