I need to access an existing database whose schema I cannot alter; I used the Django tool to extract the tables to create models.py, which worked great, and I already hacked some model definitions, e.g. to replace a simple IntegerField with a ForeignKey. But there are specific tables, where there is an IntegerField which may contain a ForeignKey from more than one table (think of a group and a user table; whether the reference is a user or a group, is defined by another column):
So what I would need here is something like a union on ForeignKey (coming from either a User or a Group table) in the model, but I guess that does not exist?
So I used raw SQL for the required joins; I have not been able to formulate a Django queryset to join on a field which is not modeled with ForeignKey.
That is why I was asking for some better support of raw SQL, reference is this ticket: https://code.djangoproject.com/ticket/34168
That's sort of how generic relations[1] work. You might be able to make it fit.
[1] https://docs.djangoproject.com/en/4.1/ref/contrib/contenttypes/#generic-relations
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.--
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/1YTjSHaj0x0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/C5E28F70-7521-4CFF-A43E-1B5576D144CF%40fattuba.com.