Conditional model creation for Django package

I’m trying to create a PR for the package django-cookie-consent and wondered what is the best way to do it:

The problem: the problem currently has a LogItem model that saves an instance whenever a cookie is accepted or denied. This takes up space FAST, so I wanted to make it an optional model.

Solutions I can think of are:

  1. Add a new setting and then check it whenever a cookie is saved or not. My question here is: does that means the user with LogItem disabled will still have an empty table created in their db? Or can I set the migration to be optional as well?

  2. Move LogItem to an app of its own. Then the user must install it to INSTALLED_APPS if they want it and each new log item would be created with… signals? … Is this a best practice, though?

Settings can be changed at any time - migrations, less so. I don’t see the problem with having empty tables in the database, it’s not like they’re going to consume a lot of space.

Your option #2 and everything else I can think of seems like it ends up being more work than it’s worth. I’d create the table and be done with it.

Ken

1 Like

Well the PR went through! I was worried having extra empty tables was frowned upon, but with @KenWhitesell’s validation I now feel lighter! :slight_smile: