-
Notifications
You must be signed in to change notification settings - Fork 24
Split mixins between fields and methods #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Having such a long chain of inheritance is maybe not the best solution, dealing with python mro and Django
|
|
@ian-foote @meshy could you have a look to this PR please? |
fdd3ce8 to
179bf9e
Compare
|
Just to clarify: it's not possible to just subclass the parent, and re-define the fields? |
|
@meshy unfortunately no :( The error message is the following: |
|
it might be related to the |
|
Aaah, I guess it is. Shame. Ok then |
|
Relevant piece of code: https://github.com/django/django/blob/d66bda60590daabe21f60a532a613a31a10fedbd/django/db/models/base.py#L229-L238 (might be fixed in the future) |
ec6f589 to
41eabc3
Compare
user_management/models/mixins.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this one for?
fe48983 to
39831d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this syntax :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If feels weird and it leaves a ): on a new line, flake8 enforce this syntax..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative is:
basic_user_mixins = (
NameUserMethodsMixin,
EmailUserMixin,
DateJoinedUserMixin,
IsStaffUserMixin,
)
class CustomBasicUserFieldsMixin(*basic_user_mixins):
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ian-foote I like this one a lot better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ): does not need to be on new line tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the syntax with the splat produces an invalid syntax error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who do you respond to? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my last message was for @ian-foote
60df2b2 to
d1e4b30
Compare
|
@ian-foote @mattack108 can you merge please? |
d1e4b30 to
f9d1749
Compare
Split mixins between fields and methods
Customising fields on
BasicUserFieldsMixinis not easy. I have a case where I need to overridenameandemail.My use case:
With the current implementation the solution is to copy
VerifyEmailMixinand its parent classBasicUserFieldsMixinto redefinenameandemailfields to avoid name clashes.It looks like splitting the current mixins to more mixins will allow redefining fields more easily.
I suggest to make
BasicUserFieldsMixinandVerifyEmailMixinchildren classes of some fields and methods.Example:
Which would allow us to create own
BasicUserFieldsMixinandVerifyEmailMixinif one or more fields need changing.