-
Notifications
You must be signed in to change notification settings - Fork 167
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
Fix object output for users
in permissions
#388
Conversation
Is it possible to go for a custom model here instead of changing the default behavior? |
Oh, that sounds like a good idea, but I have currently no idea how that works 🤔😂 There is a |
Ah ok, it's already there and doing the right thing. class Users(Record):
def __str__(self):
return self.username Looks like we need a custom model for permissions letting it know that field is a list of User objects. It being a list might present some problems though, not sure we've had to do that before 🤔 |
What's the meaning of this in pynetbox/pynetbox/core/response.py Lines 314 to 315 in 4efcab0
Does it sometimes return something else than Anyway, would a lookup table be enough for a solution?
... except that is does not work due to circular imports: I guess the current model structure is something that is based on Django ideology so I don't know what's the right+clean solution off the bat. Collecting all the models in the same source files and rewriting the model lookup logic in I'll create an issue for this (created: #389) so that we can link also the other possible PRs to that. |
Yeah, if memory serves, it shouldn't be none when a model has an attribute with an explicit reference to another model. E.g. pynetbox/pynetbox/models/dcim.py Lines 88 to 91 in ace1061
Like if this wasn't a list, I think we could build out a Permissions class under Users and bring it in something like this: class Permissions(Record):
users = Users
... Haven't had a chance to think about it too much, but I think you're on the right track in #390 with fixing up list_parser. It might be as simple as just doing a similar lookup there. |
@zachmoody Do you have have a good idea how to tackle this forward? New data models are being introduced and they have the same issue:
Not a major problem in my production applications though, only in the development stage when executing the commands interactively, still causes some raised eyebrowns 😃 How is it with the |
@zachmoody Please see PR #390, I've attempted to add support for custom model lists:
I will now modify this PR to use the |
One more comment on this PR. |
Hey @markkuleinio, apologies, haven't been able to keep up with the project as of late. Should have time to review all these next week though. |
Replaced by #419 |
The problem:
Meaning that the username "test1" is shown as an empty string. That is because
Record.__str__()
only tries to get fieldsname
andlabel
, and returns empty string if neither of those is found.This PR addresses this issue by modifying
Record.__str__()
to also tryusername
field when returning the string representation of an object.After the change: