Closed aholtheuerl closed 4 months ago
Maybe something like https://github.com/counsyl/capone#evidence-models
@aholtheuerl The way we do it is a join model.
Your question, more generically, is about polymorphism - how do I foreign-key relate multiple different models to the same model? This blog post goes over many of the different options. The join model is just one method.
class Payment
class Refund
# apps/audit/models.py
from hordak.models import Transaction
class HordakAudit
payment = models.ForeignKey(Payment...)
refund = models.ForeignKey(Refund...)
hordak_transaction = models.OneToOne(Transaction)
Benefits
Drawbacks
The simplest being, a direct link from the source object:
class Payment
hordak_transaction = models.ForeignKey(Transaction)
This works if you NEVER/RARELY have to go from hordak's Transaction looking for your source.
I would also achieve this as @nitsujri suggests. I can see an argument for pluggable models a la Django's AUTH_USER_MODEL
/ get_user_model()
, but I think that is going to introduce a bunch of complexity (and therefore maintenance overhead).
Feel free to pitch the idea to either myself of @PetrDlouhy (@PetrDlouhy is more regularly around than I am) in a new issue. But with both only work on this project occasionally, so I'd personally prize simplicity and maintainability pretty highly.
Hi! Loved the library.
It would be nice to have a way to save a document as evidence that a transaction has been made. Some way to relate the hordak transaction to the currently existing models of my app.
Does anyone know any workaround for this?