Skip to content

Instantly share code, notes, and snippets.

@cnk
Created January 31, 2018 21:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnk/5625a761993476a691bcb708ef468f6b to your computer and use it in GitHub Desktop.
Save cnk/5625a761993476a691bcb708ef468f6b to your computer and use it in GitHub Desktop.
@register_snippet
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 = [
MultiFieldPanel([
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)
@classmethod
def listing_queryset(cls, request):
return cls.objects.filter(site=request.site)
### 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)
else:
items = model.objects.all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment