Closed brylie closed 3 years ago
This issue doesn't seem to be limited to custom User
model. I can't use the "Create" Tab on my Building
model.
Below is my code for reference.
# models.py
class Event(Page):
building = models.ForeignKey("events.Building", on_delete=models.PROTECT, null=True, blank=True)
...
MultiFieldPanel(
[
FieldPanel('building', widget=BuildingChooser),
...
],
heading="Location",
),
@register_snippet
class Building(models.Model):
name = models.CharField(max_length=100, blank=False)
def __str__(self):
return self.name
# widgets.py
class BuildingChooser(AdminChooser):
choose_one_text = 'Choose a building'
choose_another_text = 'Choose a different building'
link_to_chosen_text = 'Edit this building'
choose_modal_url_name = 'building_chooser:choose'
title_field_name = 'name'
def get_instance(self, value):
self.model = apps.get_model('events', 'Building')
return super().get_instance(value)
def render_html(self, name, value, attrs):
self.model = apps.get_model('events', 'Building')
return super().render_html(name, value, attrs)
def get_edit_item_url(self, item):
return reverse('wagtailsnippets:edit', args=('events', 'building', quote(item.pk)))
# views.py
class BuildingChooserViewSet(ModelChooserViewSet):
icon = 'home'
model = Building
page_title = "Choose a building"
per_page = 10
order_by = 'name'
fields = ['name',]
@brylie I've confirmed the "Create" tab functionality works using wagtail==2.12
, but not wagtail==2.12.3
. It looks like the 2.13 streamfield updates broke this feature.
It looks like some compatibility issues where resolved in PR-31 by @gasman, but the "Create" tab may have been overlooked.
I've been poking around trying to understand Telepath, I'll post an update if I make any progress.
Turns out this is unrelated to the StreamField changes - Wagtail's tab handling was changed in https://github.com/wagtail/wagtail/commit/ca0154543aa79b463acf4a58ab45ccd8b8f6bd49 (as part of the commenting implementation) to look for a data-tab-nav
attribute on the element, rather than the existing tab-nav
classname (as used in wagtail-generic-chooser). PR coming up...
Thanks for the fix! Users are happily creating and choosing again - all is well. 🥇
I created a
UserChooserViewSet
that uses a customUser
model inheriting directly fromAbstractUser
. When I define thefields
property, the "create" tab is rendered on the chooser modal. However, clicking the "create" tab doesn't display a form:There do not appear to be any console errors.