+class WoblinkAuthorWidget(forms.Select):
+ class Media:
+ js = ("catalogue/woblink_admin.js",)
+
+ def __init__(self):
+ self.attrs = {}
+ self.choices = []
+ self.field = None
+
+ def get_url(self):
+ return reverse('catalogue_woblink_author_autocomplete')
+
+ def build_attrs(self, base_attrs, extra_attrs=None):
+ attrs = super().build_attrs(base_attrs, extra_attrs=extra_attrs)
+ attrs.setdefault("class", "")
+ attrs.update(
+ {
+ "data-ajax--cache": "true",
+ "data-ajax--delay": 250,
+ "data-ajax--type": "GET",
+ "data-ajax--url": self.get_url(),
+ "data-app-label": '',
+ "data-model-name": '',
+ "data-field-name": '',
+ "data-theme": "admin-autocomplete",
+ "data-allow-clear": json.dumps(not self.is_required),
+
+ "data-placeholder": "", # Chyba że znaleziony?
+ "lang": "pl",
+ "class": attrs["class"]
+ + (" " if attrs["class"] else "")
+ + "admin-autocomplete admin-woblink",
+ }
+ )
+ return attrs
+
+class AuthorForm(forms.ModelForm):
+ class Meta:
+ model = models.Author
+ fields = '__all__'
+ widgets = {
+ 'woblink': WoblinkAuthorWidget,
+ }
+