Feature Request: Introduce many_to_many argument in Func.render
#184
Replies: 3 comments 1 reply
-
|
Thanks for the suggestion! Writing triggers without hardcoding names has been a long-standing request in pgtrigger. There is a discussion here about using Django's templating system and template tags for things like this. I'm surprised to hear there is no way with Django's meta to reference a M2M field by name. Just tried it myself. The What I'm concerned about is if we implement this request, someone else will make a feature request to access the many_to_many of any model rather than the model over which the trigger is defined. Similar to the other discussion, what if one could write a template like this: Here Then in the trigger definition itself, you'd be able to reference the template like a django template: Thoughts on if this would help? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
@wesleykendall Utilizing a templating system sounds like an excellent idea. It should address most of the issues related to complex triggers and will certainly make maintenance easier with separate files.
Good point! A shorter solution to the problem could be: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
The
Funcclass allows for rendering SQL functions with access to the model'smeta,fields, andcolumnsvariables. However, there is currently no direct way to accessManyToManyfields by their name. The only available approach requires using positional indexing, which can lead to fragile code when models are altered.For example, to access a
ManyToManyfield, users currently have to use:{{meta.many_to_many[0].remote_field.through._meta.db_table}}Proposed Solution:
To improve this, we can modify the
rendermethod in theFuncclass to include amany_to_manyargument, allowing access toManyToManyfields by name:Then, in
Func, it would be possible to use:Benefits:
ManyToManyfields.related_nameattributes are set dynamically.Version Info:
PS: Just wanted to say a big thank you to the authors for creating such an amazing library! It’s been a huge help in our projects, and we really appreciate all the hard work you put into it. Keep up the great work! 🙌
Beta Was this translation helpful? Give feedback.
All reactions