diff --git a/apis_bibsonomy/forms.py b/apis_bibsonomy/forms.py index 3c39085..ccce5c7 100644 --- a/apis_bibsonomy/forms.py +++ b/apis_bibsonomy/forms.py @@ -20,7 +20,7 @@ def __init__(self, *args, **kwargs): self.helper = FormHelper(self) if "instance" in kwargs: self.fields["bibs_url"].widget.choices = [ - (self.initial.get("bibs_url"), self.instance.bibtex.get("title")) + (self.initial.get("bibs_url"), self.instance.get_bibtex.get("title")) ] self.helper.layout = Layout( Row( diff --git a/apis_bibsonomy/models.py b/apis_bibsonomy/models.py index e937a05..3bb647e 100644 --- a/apis_bibsonomy/models.py +++ b/apis_bibsonomy/models.py @@ -1,3 +1,4 @@ +import json from django.db import models from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType @@ -30,11 +31,17 @@ class Reference(models.Model): referenced_object = GenericForeignKey() def __str__(self): - title = self.bibtex.get("title") + title = self.get_bibtex.get("title") desc = [title, self.pages_start, self.pages_end, self.folio, self.notes] desc = ", ".join(map(str, filter(None, desc))) return desc + @property + def get_bibtex(self): + if isinstance(self.bibtex, str): + return json.loads(self.bibtex) + return self.bibtex + def get_absolute_url(self): return reverse("apis_bibsonomy:referencedetail", kwargs={"pk": self.pk}) diff --git a/apis_bibsonomy/views.py b/apis_bibsonomy/views.py index cce77a3..ea32143 100644 --- a/apis_bibsonomy/views.py +++ b/apis_bibsonomy/views.py @@ -81,7 +81,9 @@ def form_valid(self, form): ) args["object_id"] = self.request.resolver_match.kwargs["pk"] ref = Reference.objects.create(**args) - self.request.session["last_bibsonomy_reference_title"] = ref.bibtex.get("title") + self.request.session["last_bibsonomy_reference_title"] = ref.get_bibtex.get( + "title" + ) return super().form_valid(form)