iommirocks / iommi

Your first pick for a django power cord
http://iommi.rocks
BSD 3-Clause "New" or "Revised" License
718 stars 47 forks source link

Allow Meta mixins #433

Closed berycz closed 1 year ago

berycz commented 1 year ago

this small change allows Meta mixins, I talked about this on discord in #beginner (2023-08-04) dir might be a bit slower than __dict__ since it bubbles though mro, but I don't think it runs often enough to be even noticeable

My usecase is: I have 5 different tables and 6 different forms for the same model based on user "role", they differ too much to have one class but still share some properties. I use inheritance now, but I think Meta mixins would make it much cleaner

@jlubcke should check this for potential problems

berycz commented 1 year ago

hmm, is it possible the dir changed the order of links in test_edit_table? 🤔

berycz commented 1 year ago

yeah, dir() - The resulting list is sorted alphabetically :( I havent thought about it, then this PR is useless and can be closed sorry for bothering you, I forgot to test it localy first

boxed commented 1 year ago

Inheritance of the meta class? So like

class BaseMeta:
     foo = 1

class A(Table):
    class Meta(BaseMeta):
        pass   

?

berycz commented 1 year ago

yea, that's what I was trying to do, but thanks to current for key in class_.Meta.__dict__: the foo = 1 gets lost, because Meta.__dict__ does not contain properties of BaseMeta

berycz commented 1 year ago

there might be a way to go through class_.Meta.mro() and read from all of their .__dict__, not sure if it isnt too complicated or slow?

berycz commented 1 year ago

tests ok, but I havent checked if it works :D maybe a new test would be needed too but the question also is, would you agree with such a change...?

boxed commented 1 year ago

jlubcke says "helt rätt!" (absolutely correct) :P

jlubcke commented 1 year ago

I'm even a bit happy :)

berycz commented 1 year ago

nice, thanks! btw there I have value = getattr(class_.Meta, key) which might also be value = getattr(meta_class_, key), but I didn't see a reason for that, because in the end it's gonna be the same value :)