How to add new fields to third party apps' models?

Hi there,

I’m trying to add new fields to Django Group and Permission models using add_to_class method. For example, created_by and updated_by.

When I’m running migrations, the migrations files generated are going to environment files, not in my currect project folder. I have a base app, is it possible to store these migrations files inside base/migrations/auth/0012_some_migrations.py?

I need to add these fields inside other third party apps models.

There is nothing that requires you to use makemigrations to create migration files. You can create your own migrations in whatever apps you choose. (See How to create database migrations.) You could even use the makemigrations command to show you the commands being generated to use as a guide toward writing your own.

However, fundamentally this question appears to me to be an X-Y Problem. It seems to me to be the wrong approach to whatever it is you’re trying to achieve. (Changing system models seems risky - it’s a whole lot easier just to create your own Group model for your purposes and ignore the system-provided auth.Group model - that’s the approach we took. Also, relying upon an undocumented internal API isn’t something I would suggest under any circumstances.)

You could also subclass those models (multi-table inheritance) to add those new fields and whatever new functionality is needed associated with those models.

If there are reasons where that can’t work (and I can think of a couple), I think you’d still be better off forking the original code than trying to do this.

Hello Sir,

Thanks a lot for your guidance. I’ll re-analyze the requirements and solve the problem.