Drupal Views offers us a cool feature: ajaxified pagers. When you click on a pager, it changes the page without reloading the main page itself and then scrolls to the top of the view. It works great, but sometimes you may encounter a problem: if you have a fixed header on your page (the one that stays on top when you scroll the page) it will overlap with the top of your view container thus scroll to top won't work preciselly correct and the header will cover the top part of your view.

Media and static files won't be served in devel mode untill you put this at the end of the main urls.py file:

Run this line in order to start Django project by using Two Scoops of Django Project Template

It appears that Django Taggit doesn't support transliteratable tags, what we need to do is to add such support, how you may ask? We should use proxy models. Just add this piece of code to, let's say, ru_taggit.py file:

When Solr Thumbnail (https://github.com/mariocesar/sorl-thumbnail) returns and error like "SuspiciousOperation: Attempted access to '/media/products/505.jpg' denied" or Bad request: 400 you need to check the path of the image you want to resize: it shouldn't start with your MEDIA_ROOT like  '/media/products/505.jpg'.

Debugging python code is extremelly simple and powerfull. Just use ipdb for this purposes:

pip install ipdb

Then open up your code and in the place where you need code to stop insert this:

If you have a fieldgroup in a node, you may want to hide it on some conditions. Here's how to do that programmatically.

At first, we need to preprocess our node like this:

Yesterday, during a meeting with my Drupal friends, I showed them some Python magic including Fabric () and how it can be used to make your Drupal dev life easier. My friends been blown away ;) I promised to share my regular fabfile.py for a Drupal project, please see it below, just a note: this is really beginner's code and I'm not responsible for any damages or losses it can bring. Okay, here it is:

When you save your main object and want to attach / create / modify attached to it related models you need to remember the following:

1) Do this in post_save signal, because related objects need pk and you get pk in post_save (when you create a new object)

2) If you manipulate ForeignKey or OneToOneField in post_save(), no additional moves needed. Manipulate there, don't forget to save() objects after the manipulation. For example: main.related.save()

Surprise surprise! When you save a model via admin forms it's not an atomic transaction. The main object gets saved first (to make sure it has a PK), then the M2M is cleared and the new values set to whatever came out of the form. So if you are in the save() of the main object you are in a window of opportunity where the M2M hasn't been updated yet. In fact, if you try to do something to the M2M, the change will get wiped out by the clear().


Subscribe to TimOnWeb RSS