EN RU

How to use PostgreSQL partitions with Django

Article

Partitions in PostgreSQL(and MySQL too :)) are very useful when we have to store large data dividing them by attribute for future works. In my case I have logs of working on projects, which are stored in partition for each project.

Using partitions in django project is not very difficult, but there is one issue with “returning id” for insert statement in database. Function, which will insert a record to right table, must return trigger, but not id of last record as django expects.

read full ⇝

    2014-10-04 10:00:30      django postgresql partition

How to change choices for field in Django-Rest-Framework

Tip

As usual for django forms common way to change choices for some field it’s overwrite __init__ method of form and replace self.fields['<field name>'].choices. But it doesn’t work for django-rest-framework serializers.ChoiceField.

For serializers.ChoiceField you can again overwrite __init__ method and replace data in self.fields['<field name>'].choice_strings_to_values where have to be dict where key is string representation of choices "key" and value is choices "key".

like:

1
2
3
4
self.fields['fieldname'].choice_strings_to_values = {
    str(key): key
    for key, value in self.get_fieldname_choices()
}
    2016-08-26 19:00:26      django rest-framework

Django package: django-classifier

Tip

Just want to introduce my package for Django.

With help of this package you can create dynamically configurable sets of properties. Checkout tutorial for more information.

doc: http://django-classifier.readthedocs.io/

repo: https://github.com/django-stars/django-classifier

    2016-09-01 12:00:28      django package

How to Improve Django Performance. Optimization Tips

Article

I frequently face a recurring situation when developers receive a task to make a performance optimization on Django. Pretty often they are trying to make it in a wrong way. In this short article I want to shed some light on the common mistakes, and show you the way I’m searching for bottlenecks.

read full ⇝

    2017-04-11 10:00:44      django python performance

Debugging Python Applications with pdb

Article

Debugging isn’t a new trick – most developers actively use it in their work. Of course, everyone has their own approach to debugging, but I’ve seen too many specialists try to spot bugs using basic things like print instead of actual debugging tools. Or even if they did use a debugging tool, they only used a small set of features and didn’t dig deeper into the wide range of opportunities good debuggers offer. And which could have saved those specialists a lot of time.

read full ⇝

    2018-01-05 10:00:03      django python debug debugger

Django-Classifier or What Have I Done?

Article

From time to time you have to build some properties for an object and usually those are just a bunch of fields for a model. With django-classifier you may do that in another way. It allows you to create models at start, and set the properties needed from the admin panel at any time.

Let me show you two demo projects. First one is the “user profile” I’ve built for our internal website. The second one shows the way to build online store products with dynamic properties and the option to apply filters for those.

read full ⇝

    2017-03-09 10:00:37      django python data structure