django-dbsettings icon indicating copy to clipboard operation
django-dbsettings copied to clipboard

ForeignKey value

Open Natureshadow opened this issue 5 years ago • 2 comments

I was wondering whether it wouldn't be possible to have a setting holding a foreign key, or a reference to some model.

The use case is that I have a model defining a collection of objects, of which a single one can be active in the application at any time. I need to switch there in a setting.

WIlling to propose a PR if the maintainer doesn't object to it by design.

Natureshadow avatar Dec 08 '19 20:12 Natureshadow

I'd suggest to store the PK of the selected object (as a string) and have a custom logic that retrieves this dbsetting and fetches the actual entity. Would that work for you?

zlorf avatar Dec 14 '19 22:12 zlorf

I was thinking more of leveraging the contenttypes framework: https://docs.djangoproject.com/en/3.0/ref/contrib/contenttypes/

Natureshadow avatar Dec 22 '19 02:12 Natureshadow