IT Blog

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:


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...

'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')

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.


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');

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...


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...


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...

cannot alter table because it has pending trigger events

You can see error cannot alter table because it has pending trigger events when property of your fields in database is cannot change in one transaction. To understand easy you can see examples.

Romeve blank=True in fields

So, there is model:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from django.utils.encoding import python_2_unicode_compatible

class MyModel(models.Model):
    title = models.CharField(max_length=100, null=True, blank=True)
    content = models.TextField(null=True, blank=True)
    template = models.CharField(max_length=255, null=True, blank=True)

    def __str__(self):
        return self.title

So null=True is extra...

  • 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