I'm trying to add a ParentalManyToManyField relationship on save() and when I print it looks good but it doesn't seem to save for some reason.
Example code:
# Models
class BlogProduct(models.Model):
product_id = models.CharField(max_length=10, blank=False, null=False)
class ProductBlogPage(BlogDetailPage):
products = ParentalManyToManyField('blog.BlogProduct', blank=True)
product_details = StreamField(COMMON_BLOCKS + [
('product_name', blocks.ProductNameBlock()),
],
null=True,
blank=True,
use_json_field=True,
)
def save(self, *args, **kwargs):
if kwargs.get('update_fields'):
for product in self.product_details.raw_data:
blog_product, _ = BlogProduct.objects.get_or_create(product_id='test1')
# This is where I'm having trouble to connect product and snippets
self.products.add(blog_product)
self.save()
print(self.products.all())
# This prints out the querySet
# <QuerySet [<BlogProduct: TestOne>, <BlogProduct: TestTwo>]>
return super().save(*args, **kwargs)