I have a Django model which I need to hold a callable (in this case a reference to another model) to store it along with some “conditions” which should later be applied to the model.
My approach was like so:
MODEL_CHOICES = (
(django.contrib.auth.models.User, 'User'),
[some more]
)
class Model:
chosen_model = models.IntegerField(choices=MODEL_CHOICES)
conditions = models.TextField()
Conditions would look something like this:
{'status': 1, [some other]}
But obviously
django.contrib.auth.models.User
is not a valid integer.
What I try to achive is the following:
Call
chosen_model.objects.filter(**conditions)
in a view.
Is this even possible? If yes, what kind of Field do I need to store a reference to a model?
Thank you very much!
I would suggest you use the ContentType model here.