I have a streamfield which is working, and has data in, the code I wrote to do this looks something like:
class NewYearBlock(blocks.StructBlock):
year = blocks.IntegerBlock(verbose_name="Year (the year this data is rolling into)")
holidayRollover = blocks.FloatBlock(verbose_name="How many hours are rolling over")
overtimeRollover = blocks.FloatBlock(verbose_name="How many hours are rolling over")
class Meta:
icon = 'user'
and
newyearStream = StreamField([
('newyear', NewYearBlock()),
], blank=True)
What I would like to do is to append an item to this streamfield via some code, I know how to replace the item with the below (which works)
employeeModel.newyearStream = newyearStream
employeeModel.save()
But this replaces what already exists.
I was then thinking I could loop over the existing stream, and then create a new object to save, but when I try to do that I receive TypeError: cannot unpack non-iterable StreamChild object
so I looked at the type, and see it is <class 'wagtail.core.blocks.stream_block.StreamValue'>
Can anyone help point me in the right direction to either loop through the stream and get my results out, or a better way to append to my streamField.
Thanks for your time helping, Dan