If you have a parent model that has OneToOne relation to some other model and you want this child model to be created upon parent model creation you need to install django-annoying package like this:

pip install django-annoying

enable annoying app and replace your models.OneToOneField with AutoOneToOneField like this:

Surprise, surprise, when you want to perform some actions on model delete, overriding delete() method may be not enough, because when you do bulk delete of models via admin interface it won't touch model's delete() method. The way out of it is using signals:

If you've missed DrupalCon Prague 2013 or, maybe, you want to relive once again this great party go and see all videos from the event on this page: all DrupalCon 2013 Prague videos. Or use the playlist embed below. There you'll find 4 days, 7 hours long video material (104 videos)!

The easiest way to do this is to set up your script as a manage.py subcommand. Here's how to do that:

from django.core.management.base import NoArgsCommand, make_option
 

There are loads of modules that can do this for you, but why to install one more module if you can do this with one string of code? The best thing is that approach below does a redirection even if you login from user login block.


Just put the following code into your custom module:

/**
 * Implements hook_user_login().
 */
function module_name_user_login(&$edit, $account) {
  // Don't redirect on password reset.
  $current_menu_item = menu_get_item();
  if ($current_menu_item['path'] == 'user/reset/%/%/%') {
    return;
  }
  // Redirect user to profile page after the login.
  $_GET['destination'] = 'user';
}

You can find this snippet at dropbucket.org here: http://dropbucket.org/node/746
UPDATE 03/08/2013: Added several lines to prevent redirection during password reset.

I often get emails from beginner Drupal developers asking "Where to learn PHP for Drupal or Drupal PHP?". Actually, "Drupal PHP" is an interesting term, that in the language of beginners means "how to learn writing custom modules and do customizations and understand Drupal internals" that equals to learning and understanding Drupal API.

"Woa, what a long title", you must say. Yes it is and it deserves that for sure. But at first, please answer this question: "How many times you've been forced to work on client's server, because of the fact that there are services, that work only with remote server's localhost and can't be exposed to the outer world?". It could be a case with SOAP server or DB (in my case it was MSSQL) which accepts connections only from remote server's localhost.

Pages

Subscribe to TimOnWeb RSS