Skip to content

Instantly share code, notes, and snippets.

View yakky's full-sized avatar
🐢
trying to catch up with maintainer duties

Iacopo Spalletti yakky

🐢
trying to catch up with maintainer duties
View GitHub Profile
@yakky
yakky / 0001_initial.py
Last active September 15, 2023 11:12
Migrate a plugin from one type to another
from django.db import migrations
def migrate_to_new_plugin(apps, schema_editor):
OldPluginModel = apps.get_model("myapp", "PluginModel")
NewPluginModel = apps.get_model("myapp", "PluginModel")
for obj in OldPluginModel.objects.all():
#
new_obj = NewPluginModel()
new_obj.id = obj.id

Keybase proof

I hereby claim:

  • I am yakky on github.
  • I am yakky (https://keybase.io/yakky) on keybase.
  • I have a public key ASDMqW3a9lVYExJgJr_JbcDe04hCRO2T-vQPKKn2lMCaDAo

To claim this, I am signing this object:

@yakky
yakky / 0000_README.rst
Last active June 25, 2016 14:05
Migrate to filer ThumbnailOption
  1. Add the discovery of proper ThumbnailOption model in you app models.py
  2. Create a manual migration like in example_migration.py
  3. In every migration (even existing ones) add:

    from custom_plugins.models import thumbnail_model
  4. In every migration (even existing ones) replace 'cmsplugin_filer_image.ThumbnailOption' with thumbnail_model like here https://github.com/nephila/djangocms-blog/blob/develop/djangocms_blog/migrations/0001_initial.py#L12 -> https://github.com/nephila/djangocms-blog/blob/develop/djangocms_blog/migrations/0001_initial.py#L108
# Changing field 'Post.main_image_full'
db.alter_column(u'djangocms_blog_post', 'main_image_full_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['filer.ThumbnailOption']))
# Changing field 'Post.main_image_thumbnail'
db.alter_column(u'djangocms_blog_post', 'main_image_thumbnail_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, on_delete=models.SET_NULL, to=orm['filer.ThumbnailOption']))
# Changing field 'Post.main_image_full'
db.alter_column(u'djangocms_blog_post', 'main_image_full_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['cmsplugin_filer_image.ThumbnailOption'], on_delete=models.SET_NULL))
@yakky
yakky / pico.py
Last active March 16, 2018 09:36
Micro hello world Python Web Framework Royal Rumble @PyCon 7
import django
DEBUG, ROOT_URLCONF, DATABASES, SECRET_KEY = 1, 'pico', {'default': {}}, 'p'
urlpatterns = [django.conf.urls.url(r'^(?P<name>\w+)?$', lambda request,
name: django.http.HttpResponse('hello %s!' % (name or 'world')))]
TypeError at /de/admin/aldryn_categories/category/7/delete/
delete() takes exactly 1 argument (2 given)
Request Method: POST
Request URL: http://myproject-dev.domain.com/de/admin/aldryn_categories/category/7/delete/
Django Version: 1.6.10
Exception Type: TypeError
Exception Value:
delete() takes exactly 1 argument (2 given)
Exception Location: /home/myproject-dev/app/local/lib/python2.7/site-packages/parler/models.py in delete, line 537
Python Executable: /home/myproject-dev/app/bin/python
Django==1.7
https://github.com/divio/django-cms/archive/develop.zip
django-reversion==1.8.2
https://github.com/divio/djangocms-text-ckeditor/archive/master.zip
https://github.com/divio/djangocms-admin-style/archive/master.zip
https://github.com/divio/djangocms-column/archive/master.zip
https://github.com/divio/djangocms-style/archive/master.zip
https://github.com/divio/djangocms-file/archive/master.zip
https://github.com/divio/djangocms-flash/archive/master.zip
https://github.com/divio/djangocms-googlemap/archive/master.zip
class ProductAdmin(admin.ModelAdmin):
list_display = ('name','thumb')
def thumb(self, obj):
return render_to_string('thumb.html',{
'image': obj.image
})
thumb.allow_tags = True
@yakky
yakky / djangocms_blog_import.py
Last active May 6, 2020 21:50
Import posts from wordpress to djangocms_blog
def import_wp(language):
from django.template.defaultfilters import truncatewords_html
from cms.api import add_plugin
from wordpress.models import Post as WPost
from djangocms_blog.models import Post, BlogCategory
from django.contrib.auth.models import User
for post in WPost.objects.published():
print post.title

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta charset='UTF-8'>
<meta name='keywords' content='your, tags'>
<meta name='description' content='150 words'>
<meta name='subject' content='your website's subject'>
<meta name='copyright' content='company name'>