Instantly share code, notes, and snippets.

@cnk /
Created Jan 31, 2018

What would you like to do?
class Author(models.Model):
first_name = models.CharField(max_length=128)
last_name = models.CharField(max_length=128)
site = models.ForeignKey('wagtailcore.Site', on_delete=models.CASCADE)
panels = [
FieldPanel('first_name', classname='col6 first-name'),
FieldPanel('last_name', classname='col6 last-name'),
], classname='author-name'),
class Meta:
unique_together = ["first_name", "last_name"]
ordering = ['last_name', 'first_name']
def __str__(self):
return "{1}, {0}".format(self.first_name, self.last_name)
def listing_queryset(cls, request):
return cls.objects.filter(
### Then make the following change (original just calls items = model.objects.all() for all models)
def choose(request, app_label, model_name):
model = get_snippet_model_from_url_params(app_label, model_name)
if getattr(model, 'listing_queryset', None) and callable(model.listing_queryset):
items = model.listing_queryset(request)
items = model.objects.all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment