A simple script to update a DB migration in Django 1.7+

During the development of a Django model on your local machine is it often necessary to refine the most recent migration to cope with updates to the model, without polluting the migrations of the app with a new migration for each local update.

South had the update flag for the schemamigration command, but I didn’t find a similar functionality in the Django builtin makemigrations command introduced in Django 1.7.

So I put togheter a simple bash script to automate the process.

Read More »

How to add a group choice combo box in a Django user profile form

Assume that you have a Django project where each user belongs to just one group, say Registered or Admin, but not both.

You want to show a form in your front-end to let Admin users edit the user profiles, where each user profile is made with First name, Last name, Email and the user group.

This task can be accomplished very easily! What you need is a customized ModelForm to add the possibility to edit the user group together with the other fields, and a customized UpdateView to let you set the form initial data for the group field, and to save the changes correctly.

Read More »