Last active
July 21, 2018 23:23
-
-
Save KalobTaulien/10f9cae6c7f38d2e62679b4d8e710d69 to your computer and use it in GitHub Desktop.
Wagtail 2: Creating a new Snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Register a custom Wagtail Snippet.""" | |
from django.db import models | |
from wagtail.admin.edit_handlers import FieldPanel | |
from wagtail.snippets.models import register_snippet | |
class Category(models.Model): | |
"""Category information.""" | |
# Categoy Name | |
name = models.CharField(max_length=255) | |
# Used for sorting | |
order = models.IntegerField(default=0) | |
class Meta: | |
"""Provide meta information.""" | |
verbose_name = 'Category' | |
verbose_name_plural = 'Categories' | |
ordering = ['order'] | |
panels = [ | |
FieldPanel('name'), | |
FieldPanel('order'), | |
] | |
def __str__(self): | |
"""Return string representation of class.""" | |
return self.name | |
register_snippet(Category) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment