Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Snippet title problem after upgrade from wagtail 1.13 to 2.0

I am working on wagtail upgrade on a site from version 1.13.4 . Was mostly following this post https://wagtail.org/blog/upgrading-wagtail/ . However, since the first update to wagtail 2.0 snippet titles are wrong. I could sort it out on the templated front end pages, but they still appear wrong on the admin panel.

How titles are displayed on the admin panel
And this same issue is with fields that link to those snippets

I got as far as updating wagtail to 2.4, since the blog post said that it should support python 3.7, but issue still persists. As far as I can tell, there are no error messages on the terminal output, migrations run without any issues. Any clue where I should start looking?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This should be the relevant artist snippet declaration from the project

@register_snippet
class Artist(index.Indexed, models.Model):
    class Meta:
        ordering = ['name']

    def __unicode__(self):
        return unicode(self.name)

    objects = ArtistQuerySet.as_manager()

    name = models.CharField(max_length=512)
    name_encoded = models.CharField(max_length=512)
    image_url = models.URLField(blank=True, max_length=512)
    image = models.ForeignKey(
        'wagtailimages.Image',
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
        related_name='+',
    )

    @property
    def status(self):
        # If there are no events currently attached to this artist
        if not self.artistatevent_set.all():
            return NO_CURRENT_DATES

        # This artist does have some events, next see if there's any tickets
        if self.total_ticket_count is not 0:

            # Are they all the same type?
            if self.available_ticket_count == self.total_ticket_count:
                return AVAILABLE
            if self.sold_out_ticket_count == self.total_ticket_count:
                return SOLD_OUT
            if self.cancelled_ticket_count == self.total_ticket_count:
                return CANCELLED
            if self.unavailable_ticket_count == self.total_ticket_count:
                return UNAVAILABLE

        # See if we have ANY of the following
        if self.available_ticket_count:
            return AVAILABLE
        if self.coming_soon_ticket_count:
            return COMING_SOON
        if self.sold_out_ticket_count:
            return SOLD_OUT

        # Nothing matched, so default
        return UNAVAILABLE

    panels = [
        FieldPanel('name'),
        ImageChooserPanel('image'),
    ]

    search_fields = [
        index.SearchField('name', partial_match=True),
    ]


EDIT:

This is a snippet from admin.py declaration

...
class NameIDAdmin(admin.ModelAdmin):
    list_display = ('name', 'id')
...
admin.site.register(Artist, NameIDAdmin)

>Solution :

When upgrading from Python 2 to 3, you should replace the __unicode__ method with __str__: https://docs.djangoproject.com/en/1.10/topics/python3/#str-and-unicode-methods

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading