I am using Django admin for managing my data. I have a Users, Groups and Domains tables Users table has many to many relationship with Groups and Domains tables. Domains table has one to many relationship with Groups table. and when I save the User data through admin I also need some addtional database updates in the users_group and the users_domains table. How do I do this? Where do I put the code. Thanks.
I think you are looking for InlineModels. They allow you to edit related models in the same page as the parent model. If you are looking for greater control than this, you can override the ModelAdmin save methods.
Also, always check out the Manual when you need something. It really is quite good.
Paolo: Looks like I need to override the save method. As I mentioned before I need to update a couple of database tables... and let rest of the operations perform as usual. How do I do that. Thanks
The best way to update other database tables is to perform the necessary get and save operations. However, if you have a many-to-many relationship, by default, both sides of the relationship are accessible from a _set parameter. That is, user.group_set.all() will give you all Group objects associated with a user, while group.user_set.all() will give you all User objects associated with a group. So if you override the save method (or register a signal listener--whichever option sounds stylistically more pleasing), try:
for group in user.group_set.all():
#play with group object
....
group.save()