0

I have a model User. For performance and other reasons I have to split this Model and its table into two, UserA and UserB. I decided to use materialized views (with the help of django-pgviews). Now what IS easy is to query the data of UserA which is already in the table, like the username or password. What doesn't work are reverse relationships. Let's say I have a Checkout model and in this:

user = models.ForeignKey(User, on_delete=models.SET_NULL, related_name='checkouts')

When I try to access user.checkouts, it of course throws an error: Cannot resolve keyword 'checkouts' into field.

So how can I create a reverse relationship which is accessible from multiple models? I thought about using contenttypes but this seems a bit much for this use case, especially because UserA and UserB are just views and have the same columns.

Tim
  • 929
  • 1
  • 14
  • 28
  • "user.checkouts" - is "user" referencing to specific row of model "User"? Could you please post your models.py – B.Anup Mar 10 '22 at 03:34
  • "user.checkouts" is the reverse relationship defined via `user = models.ForeignKey(User, on_delete=models.SET_NULL, related_name='checkouts')`, more verbose: `UserA.objects.filter(pk=1).first().checkouts.all()` – Tim Mar 10 '22 at 07:45

0 Answers0