1๐
โ
cms.Page
objects exist in published and draft form, and the draft (along with all the objects associated with it) is copied to the other version in the Publish operation.
Your MyAppExtension.objects
have ManyToManyField
attributes. These will need to be copied too, otherwise the published version will fail โ as you have discovered โ to get back to these objects.
Handling relations in the documentation for Page extensions explains what to do and gives an example โ in brief, provide a copy_relations()
method on the Page extension, that copies them to the new instance.
Without this method youโll find that all copy operations on the page, not just publishing, fail to copy the objects.
๐คDaniele Procida
0๐
Maybe you can use something like this:
class PageDataExtension(PageExtension):
category_page = models.ManyToManyField(category, blank=True)
def copy_relations(self, oldinstance, language):
self.category_page.clear()
for pcategory in oldinstance.category_page.all():
self.category_page.add(pcategory)
๐คdarthwiin
- Add my own class in admin field django-cms
- Django formset โ surplus line is rendered in the table
- Django return render template and Json response
- How do use Foreign Key in slug django
- Django save multiple user types
Source:stackexchange.com