I have the following model in a wagtail app:
class JoinusRegistration(models.Model):
user_info = models.ForeignKey('JoinusUserFormBuilder', default=1, on_delete=models.CASCADE)
event_name = models.ForeignKey('JoinusEvent', default=1, on_delete=models.CASCADE)
registration_date = models.DateTimeField(auto_now_add=True, blank=True)
wait_list = models.BooleanField(default=0)
def name(self):
user_info = str(self.user_info).replace("'", '"')
json_loads = json.loads(user_info)
return json_loads['your_name']
def __str__(self):
return self.event_name.title
class Meta:
verbose_name = "Event Registration"
And the following SnippetViewSet in a wagtail_hooks.py file:
class JoinusRegistrationAdmin(SnippetViewSet):
model = JoinusRegistration
menu_label = 'Registrations'
icon = 'doc-full'
base_url_path = 'reg'
list_display = ('name', 'event_name', 'registration_date' ,'wait_list')
filterset_class = FilterByEvent
edit_view_class = JoinusRegistrationEditView
On the index view of the admin, I'm able to create a custom display for the user_info field (necessary because user_info is form data saved as JSON) by creating a function called name, and adding it the list_display tuple of the SnippetViewSet. It looks like this:
Is there any way to re-rewrite the user_info field in the edit view? The default behavior is less than ideal:
I tried writing my own custom edit_view_class but could not get anything to work. EX:
class JoinusRegistrationEditView(EditView):
def show_me_something(self):
show_id = self.user_info.objects.id
return show_id`