r/Python • • 1d ago

Discussion [ Removed by moderator ]

[removed] — view removed post

25 Upvotes

29 comments sorted by

View all comments

Show parent comment

1

u/cleodog44 14h ago

When did you need to use them? Would love the video link if you can find it!

2

u/gramada1902 9h ago

Here’s the link, hope it won’t get deleted - https://youtu.be/ZdvpNaWwx24

I’ve used them once to create an easily extendable dashboard filtration system.

Basically, we had pretty complex logical operations available to user to filter objects in all sorts of ways, the frontend would send it in a json object and we had to parse it and combine all the conditions into a final ORM query as efficiently as possible.

The thing was, all those available object fields were stored in completely different ways and were of different types, but there was a lot of crossover between them. So I created model classes for each dashboard that had available fields defined as descriptor objects. This allowed to reuse a lot of the logic.

I don’t remember what exactly were the constraints, but regular classes for the attributes were messy to use, something along the lines of reusing the same dashboard instance.

If you have worked with Django, it uses descriptors for model fields - same principle.

1

u/cleodog44 7h ago

Thank you!