Add ManyToManyAdminField for use with ManyToManyField#43
Add ManyToManyAdminField for use with ManyToManyField#43Furkanzmc wants to merge 8 commits intoebertti:mainfrom
Conversation
2 similar comments
| super(SimpleAdminField, self).__init__(short_description, admin_order_field, allow_tags) | ||
|
|
||
| def __name__(self): | ||
| return 'SimpleAdminField' |
There was a problem hiding this comment.
Can you send me the warning message from django?
There was a problem hiding this comment.
'ForeignKeyAdminField' object has no attribute '__name__'
When used like this
price_model_link = ForeignKeyAdminField('price_model')
readonly_fields = (
price_model_link,
)
There was a problem hiding this comment.
What do you think about put this way:
def __name__(self):
return self.__class__.__name__It will work for all child classes with right name.
| return self.default | ||
|
|
||
|
|
||
| class ManyToManyAdminField(SimpleAdminField): |
There was a problem hiding this comment.
I will improve the coverage by the way. I put it together after using it myself, but I haven't had time to improve the testing.
| if hasattr(ref, 'get_queryset'): | ||
| list_str = '<ul>' | ||
| objects = ref.get_queryset() | ||
| for obj in objects: |
There was a problem hiding this comment.
What do think about using string template to replace this code?
| class ManyToManyAdminField(SimpleAdminField): | ||
| """Renders a ManyToManyField as links.""" | ||
|
|
||
| def __init__(self, attr, display=None, short_description=None, admin_order_field=None, default=None): |
There was a problem hiding this comment.
I think will be great to add a template path. to help on customization from user.
then you check
if template_path:
# use template
else:
# use default way|
If you need some help to fix the broked tests on django 2.0, please, ask me. Thanks for your PR |
I've added a field to show the objects of a many to many field in a list. And I added a
__name__method toSimpleAdminFieldbecause Django was complaining that__name__could not be found.