from django_inlines.inlines import TemplateInline from darkroom.models import Photo class PhotoInline(TemplateInline): """ An inline that takes a darkroom photo id, slug, or just a url returns a photo template with proper width and height. Examples:: {{ photo 34 }} The inluded template supports width and height arguments:: {{ photo 32 size=small }} """ help_text = ( "Takes a darkroom photo id or slug and returns a template for the photo." ) inline_args = [dict(name="size", help_text="Small/Medium/Large/Full")] def get_context(self): try: photo = Photo.objects.get(pk=self.value) except: photo = Photo.objects.get(slug=self.value) return {"photo": photo} class GraphicInline(TemplateInline): """ An inline that takes a darkroom graphic id, slug, or just a url returns a template with size and position classes set. Examples:: {{ graphic 34 }} The inluded template supports width and height arguments:: {{ graphic 32 size=small float=right }} """ help_text = ( "Takes a darkroom graphic id or slug and returns a template for the graphic." ) inline_args = [dict(name="size", help_text="Small/Medium/Large/Full")] def get_context(self): try: photo = Graphic.objects.get(pk=self.value) except: photo = Graphic.objects.get(slug=self.value) return {"graphic": graphic}