You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							61 lines
						
					
					
						
							1.6 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							61 lines
						
					
					
						
							1.6 KiB
						
					
					
				
								from django.db import models
							 | 
						|
								
							 | 
						|
								from modelcluster.fields import ParentalKey
							 | 
						|
								
							 | 
						|
								from wagtail.core.models import Page, Orderable
							 | 
						|
								from wagtail.core.fields import RichTextField
							 | 
						|
								from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
							 | 
						|
								from wagtail.images.edit_handlers import ImageChooserPanel
							 | 
						|
								from wagtail.search import index
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								class CategoryList(Page):
							 | 
						|
								    intro = RichTextField(blank=True)
							 | 
						|
								    image = models.ForeignKey(
							 | 
						|
								        'wagtailimages.Image', on_delete=models.CASCADE, related_name='+'
							 | 
						|
								    )
							 | 
						|
								
							 | 
						|
								    parent_page_types = ['home.HomePage', ]
							 | 
						|
								
							 | 
						|
								    content_panels = Page.content_panels + [
							 | 
						|
								        FieldPanel('intro', classname="full"),
							 | 
						|
								        ImageChooserPanel('image'),
							 | 
						|
								    ]
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								class Product(Page):
							 | 
						|
								    price = models.PositiveIntegerField()
							 | 
						|
								    description = RichTextField(blank=True)
							 | 
						|
								
							 | 
						|
								    def main_image(self):
							 | 
						|
								        gallery_item = self.gallery_images.first()
							 | 
						|
								        if gallery_item:
							 | 
						|
								            return gallery_item.image
							 | 
						|
								        else:
							 | 
						|
								            return None
							 | 
						|
								
							 | 
						|
								    parent_page_types = ['catalog.CategoryList', ]
							 | 
						|
								
							 | 
						|
								    search_fields = Page.search_fields + [
							 | 
						|
								        index.SearchField('description'),
							 | 
						|
								    ]
							 | 
						|
								
							 | 
						|
								    content_panels = Page.content_panels + [
							 | 
						|
								        FieldPanel('price'),
							 | 
						|
								        FieldPanel('description', classname="full"),
							 | 
						|
								        InlinePanel('gallery_images', label="Obrázky"),
							 | 
						|
								    ]
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								class ProductImage(Orderable):
							 | 
						|
								    page = ParentalKey(BlogPage, on_delete=models.CASCADE, related_name='product_images')
							 | 
						|
								    image = models.ForeignKey(
							 | 
						|
								        'wagtailimages.Image', on_delete=models.CASCADE, related_name='+'
							 | 
						|
								    )
							 | 
						|
								    caption = models.CharField(blank=True, max_length=250)
							 | 
						|
								
							 | 
						|
								    panels = [
							 | 
						|
								        ImageChooserPanel('image'),
							 | 
						|
								        FieldPanel('caption'),
							 | 
						|
								    ]
							 | 
						|
								
							 |