Fixtures and Streamfields

350 views
Skip to first unread message

Ben Wattie

unread,
Aug 2, 2015, 11:55:19 PM8/2/15
to Wagtail support
Hello,

I created fixtures from dumpdata (wagtailimages, wagtaildocs, wagtailcore, and some custom apps)
When loading these fixtures from a blank migrate, imagechooserblock and documentchooserblock  in streamfields do not get their respective files, they are just empty.
All other models including normal image fields are loaded fine.

Here is my homepage as an example.
Logo is loaded fine, as is icon.
Carousel captions and links get loaded fine.
But imagechooserblock from streamfield is empty.
{
   
"fields": {
       
"body": "<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corporis rem repellat maxime porro ipsam nisi officiis repellendus, tempora recusandae molestiae, incidunt quibusdam necessitatibus explicabo quasi aperiam eligendi dolorem dolor obcaecati.</p>",
       
"logo": 23,
       
"carousel": "[{\"type\": \"carousel\", \"value\": {\"caption\": \"caption #1\", \"image\": 5, \"link\": \"\"}}, {\"type\": \"carousel\", \"value\": {\"caption\": \"\", \"image\": 6, \"link\": \"http://example.com\"}}, {\"type\": \"carousel\", \"value\": {\"caption\": \"Apply now\", \"image\": 7, \"link\": \"http://example.com\"}}]",
       
"icon": 23
   
},
   
"model": "core.homepage",
   
"pk": 4
},


The same goes for documentchooserblock in other streamfields.

Is this a bug or am I doing something wrong?

Matthew Westcott

unread,
Aug 4, 2015, 4:56:05 AM8/4/15
to wag...@googlegroups.com
Hi Ben,
Could you share your Homepage class definition, please?

Cheers,
- Matt

Ben Wattie

unread,
Aug 4, 2015, 11:43:01 PM8/4/15
to Wagtail support
#this blocks image does not get loaded from fixture
class CarouselBlock(StructBlock):
    image
= ImageChooserBlock(icon='image')
    caption
= CharBlock(blank=True, null=True, required=False)
    link
= URLBlock(blank=True, null=True, required=False)

   
class Meta:
        label
= "Carousel Block"
       
template = "blocks/carousel.html"

class CarouselHomeBlock(StreamBlock):
    carousel
= CarouselBlock()

   
class Meta:
       
template = 'blocks/carousel_home.html'
        label
= 'Carousel'

class HomePage(Page):
   
#subpage_types
    logo
= models.ForeignKey(
       
'wagtailimages.Image',
       
null=True,
        blank
=True,
        on_delete
=models.SET_NULL,
        related_name
='+'
   
)
    icon
= models.ForeignKey(
       
'wagtailimages.Image',
       
null=True,
        blank
=True,
        on_delete
=models.SET_NULL,
        related_name
='+'
   
)
    carousel
= StreamField(CarouselHomeBlock(), null=True, blank=True)
    search_fields
= ()
    body
= RichTextField(blank=True)

   
#custom properties and unicode() children() get_context() etc..

   
class Meta:
        verbose_name
= "Home page"


    content_panels
= [
       
MultiFieldPanel(Page.content_panels + [
           
FieldPanel('body', classname="full"),
       
], "Base"),
       
StreamFieldPanel('carousel'),
   
]


    promote_panels
= [
       
MultiFieldPanel(Page.promote_panels, "Common page configurations"),
       
MultiFieldPanel([
           
ImageChooserPanel('logo'),
           
ImageChooserPanel('icon'),
       
], "Display")
   
]


Actually the home page has related links as well but thats not in the JSON, and a lot of class definitions so I left it out. 

Matthew Westcott

unread,
Aug 6, 2015, 6:41:42 AM8/6/15
to wag...@googlegroups.com
Hi Ben,
I've not been able to replicate the issue here. The steps I followed are:

wagtail start myproject
cd myproject
./manage.py migrate

Edit home/models.py to contain https://gist.github.com/gasman/cc65b011e9783dead200

./manage.py makemigrations
./manage.py migrate
./manage.py createsuperuser
./manage.py runserver

log in to http://localhost:8000/admin/
edit homepage, add a carousel item with an image and caption
publish the homepage

./manage.py dumpdata contenttypes wagtailcore wagtailimages home > dump.json
(at first I left out contenttypes, but that caused page types to be assigned wrongly on load)

rm db.sqlite3
./manage.py migrate
./manage.py createsuperuser
./manage.py loaddata dump.json

Edit homepage - carousel image is still present.

Cheers,
- Matt
> --
> You received this message because you are subscribed to the Google Groups "Wagtail support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wagtail+u...@googlegroups.com.
> To post to this group, send email to wag...@googlegroups.com.
> Visit this group at http://groups.google.com/group/wagtail.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/wagtail/92caf29d-ea17-408a-93c1-2f2928fec2b8%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ben Wattie

unread,
Aug 9, 2015, 6:00:11 AM8/9/15
to Wagtail support
Thank you, I can confirm that it works fine with those steps.

Turns out I was missing some renditions fixtures
Reply all
Reply to author
Forward
0 new messages