IT Blog

Adding copy_relations outside of plugin using signals in django cms

In django-cms, it is sometimes necessary to add or extend copy_relations() in a third party plugin model to handle foreign keys: ForeignKey, OneToOneField или ManyToManyField.

For example, there is a certain third-party application (cms plugin) text_block with the TextBlock model:

# models.py
class TextBlock(CMSPlugin):
    title = models.CharField(_('Title'), max_length=255)
    content = models.TextField(_('Content'))


# cms_plugins.py
class TextBlockPlugin(CMSPluginBase):
    model = TextBlock
    name = 'TextBlock'
    render_template = 'text_block.html'

And we need to add some extra field, for example, description.

To do this, add a new application to the project, for example, text_block_ext with the TextBlockExt model:

class TextBlockExt(models.Model):
    text_block =...
Go

django-cms this.ui.container.data(...).push is not a function

In django 3.7.X (possibly in an earlier version) until current 3.8.0 (at the time of writing) has an error when opening the page structure:

`Uncaught TypeError: this.ui.container.data(...).push is not a function
at s.initialize (bundle.toolbar.min.js:1)

It occurs when the template has several static_templates with the same names, for example: {% static_placeholder 'header' %}.

There is an issue on Github, and developers have not fixed this case at this moment.

By digging around in the bundle.toolbar.min.js file where the error occurs, I was able to find a workaround.

Workaround

Copy /path_to_env_of_my_project/lib/python3.8/site-packages/cms/static/cms/js/dist/3.8.0/bundle.toolbar.min.js file to /path_to_my_project/static/cms/js/dist/3.8.0/bundle.toolbar.min.js.

Note that instead of the 3.8.0...

Go

django-select2 in Django

Immediately use django_select2 in the Django admin does not work because django_select2 requires jQuery. By default django_select2 widget does not include jQuery. You can read more about this on .

To quickly add jQuery to django_select2, do the following:

Go

Key (extended_object_id) already exists.

When publishing a page in django-cms (3.5.0), an error may occur:

django.db.utils.IntegrityError: duplicate key value violates unique constraint "spec_pageext_extended_object_id_key"
DETAIL:  Key (extended_object_id)=(324) already exists.

From treysbeka it is clear that the error is related to Extension (PageExtension).

Still need to say that the error does not always appear when publishing the page. To reproduce the error you need:

  1. Create an extension (or "Save" in another way from Menu / Page / My extension)
  2. Publish page
  3. Go to the draft version by clicking "Edit"
  4. Remove extension (by going to Menu / Page / My extension and clicking "Delete")
  5. Create an extension...
Go

'NoneType' object has no attribute 'get_all_fields' parler

If you create your own migration to add fields that must be translatable, you get error:

'NoneType' object has no attribute 'get_all_fields'

1 case. Update parler

In newer versions of parler, this error has been fixed, so it’s enough to upgrade the package.

2 case. Add TranslatableModelMixin in base class of model

Just addMyModel.__bases__ = (models.Model, TranslatableModelMixin) after declaration of MyModel.

For clarity, take an and add the necessary line:

from django.db import migrations
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist


def forwards_func(apps, schema_editor):
    MyModel = apps.get_model('myapp', 'MyModel')
    MyModel.__bases__ = (models.Model, TranslatableModelMixin)
    MyModelTranslation = apps.get_model('myapp', 'MyModelTranslation')...
Go

Add jquery to widget Django

There is two simple ways to add jQuery to forms or widgets in django admin.

1. Adding of an other version of jQuery

Firstly, you need . As an example for this article I used . Place library, for example, here: my_project/static/jquery/jquery-2.2.0.min.js.

Go

Highcharts redraw diagrams

Typically, highcharts graphics are automatically redrawn when the browser window is changed, but sometimes you need to forcefully redraw graph.

Intuition suggests you need to use .redraw() method, but, alas, it probably will not work (as it happended with me). For example, I had to redraw diagram after minimizing of left menu bar. When the menu collapses or unfolds, then width of div changes, and it need to automatically adjust the graphics to new width.

To redraw the highcharts diagrams, use .reflow() method:

$('..close').on('click.chart', function () {  // add click event on minimize menu button
    var $sb_chart = $('.sb_chart');
    $.each($sb_chart,...
Go

tar archive

tar archive creation

tar -cvf file.tar /path/to/file_or_folder/   # create .tar

With .tar.gz and .tar.bz2 formats you can use the compression:

tar -czvf file.tar.gz /path/to/file_or_folder/   # create .tar.gz (popular)
tar -cjvf file.tar.bz2 /path/to/file_or_folder/   # create .tar.bz2

Extract .tar archive

tar -xvf file.tar.gz

Keys of tar command

-c - to create archive
-v - listing of handled files
-f - working with file
-z - archive compression with gzip
-j - archive compression with bzip2
-x - file extract from archive
-C - to go to folder (look more detail below)

More details with compression

Do you note that when you extract...

Go

Development of Levels social network

Dear readers!

I'm glad to show you my new Levels project -

Levels is social network for athletes and people, who conduct active and healthy a way of life. Goals of project are create the platform, where people would can read interesting articles about health and motivation, find various dishes, draw up a plan of training and nutrition, and also talking to other people, that conduct correct a way of life too. In general, I want to inspire people to improve their life energy, thanks to the development of body and spirit, right nutrition, building of positive thoughts and so...

Go

html_content with attachment in django-post_office

I get strange bug with attachment in django-post-office (at least, it's encountered in version 2.0.8 and lower): when the mail is sent, which consist of html-content with attachment (of any format), the mail is come, but without attachment.

I used next package version:

django==1.10.7 (and lower)
django-post-office==2.0.8 (and lower)

In more detail, the behavior of django-post-office of the specified version and the working of the mail.send() method can be described as follows:

  1. When the mail is sent with simple content, using message parameter, and with attachment - it works correctly, i. e. I get mail with attachment.
  2. When the mail...
Go
  • Page 1 from 2
  • Pages:
  • 1
  • 2
  • Next

There is no search on this site, so I offer to use usual search engine, for example, Google, adding "vivazzi" after your request.

Try it

Select currency for displaying monetary values