Skip to content
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

date_hierarchy on related fields in ForeignKey doesn't work. #244

Closed
FraCata00 opened this issue Jan 20, 2023 · 23 comments
Closed

date_hierarchy on related fields in ForeignKey doesn't work. #244

FraCata00 opened this issue Jan 20, 2023 · 23 comments
Assignees
Labels
bug Something isn't working

Comments

@FraCata00
Copy link
Contributor

Python version
3.10.6

Django version
3.2.16

Package version
0.24.2

Current behavior (bug description)
if in modeladmin set the date_hierarchy with a field inside the ForeignKey, not work, maybe because not work the template_tags, so i read that inside this, search for the fields of Models, so the fk__fields is not a field of the chilld model

Expected behavior
?

@FraCata00 FraCata00 added the bug Something isn't working label Jan 20, 2023
@FraCata00
Copy link
Contributor Author

FraCata00 commented Jan 20, 2023

like this

class ChildModel(admin.ModelAdmin):
          date_hierarchy = "fk__parent_fields"

exception like this:

FieldDoesNotExist at /it/app/model/

Model has no field named "fk_model__parent_field"

i think the problem is in this functions of template_tags in admin_interface/templatetags/admin_interface_tags.py, line 135, in admin_interface_date_hierarchy_removal_link

@register.inclusion_tag("admin_interface/date_hierarchy_removal_link.html")
def admin_interface_date_hierarchy_removal_link(changelist, date_field):
       date_label = changelist.model._meta.get_field(date_field).verbose_name
        ...........................etc

@fabiocaccamo
Copy link
Owner

@FraCata00 thank you for reporting this.
Yes, I agree with you, the error is in the template tag.

Just for being 100% sure, does it work correctly if you don't use django-admin-interface?

@FraCata00
Copy link
Contributor Author

@fabiocaccamo yes it work 100%

@FraCata00
Copy link
Contributor Author

@fabiocaccamo if U want, after work I can fix that, I try

@fabiocaccamo
Copy link
Owner

@FraCata00 if you can submit a PR it would be great!

@FraCata00
Copy link
Contributor Author

@fabiocaccamo Great!! Try to fix in this weekend

@FraCata00
Copy link
Contributor Author

@FraCata00 if you can submit a PR it would be great!

Sorry, how can I start the project? Any docker or docker-compose file doesn't exists

@FraCata00
Copy link
Contributor Author

See https://docs.djangoproject.com/en/4.1/intro/tutorial01/#creating-a-project and https://github.com/fabiocaccamo/django-admin-interface#installation

Man,I'm a Django developer in a Italy software house😅
I know that but my question is how start a development place only for this app

@merwok
Copy link
Contributor

merwok commented Jan 22, 2023

Well you can’t expect people to guess your experience level!

This project doesn’t have a demo app, so you have to write one to test the effect of changes, or rely on unit tests.

@FraCata00
Copy link
Contributor Author

Ohhh okay,really good point 🫶🏼
Thanks for the comment!

@FraCata00
Copy link
Contributor Author

I tried to reproduce this bug, but the bug only appears if a custom theme is active...
with default theme called "Django" the bug isn't reproduced
@fabiocaccamo

@fabiocaccamo
Copy link
Owner

fabiocaccamo commented Jan 24, 2023

@FraCata00 all themes are handled by the same logic, the only things that can differ are their options, so I suppose that the theme that causes the problem has list_filter_removal_links set, instead in the default theme that option is not set (by default).

@FraCata00
Copy link
Contributor Author

@FraCata00 all themes are handled by the same logic, the only things that can differ are their options, so I suppose that the theme that causes the problem has list_filter_removal_links set, instead in the default theme that option is not set (by default).

I also think that the problem is there, because it triggers that function by setting a custom theme

@merwok
Copy link
Contributor

merwok commented Jan 24, 2023

I added that template tag, feel free to ask any question or tag me if you make a PR!

@FraCata00
Copy link
Contributor Author

I added that template tag, feel free to ask any question or tag me if you make a PR!

Amazing work man, so I'd like to fix that when a custom theme is set

@merwok
Copy link
Contributor

merwok commented Jan 24, 2023

This is how the date_hierarchy template tag gets the field object from a string: https://github.com/django/django/blob/main/django/contrib/admin/templatetags/admin_list.py#L356

The function used there must handle __ segments, which my simple code changelist.model._meta.get_field doesn’t.
So changing this line should do it!

@FraCata00
Copy link
Contributor Author

FraCata00 commented Jan 24, 2023

This is how the date_hierarchy template tag gets the field object from a string: https://github.com/django/django/blob/main/django/contrib/admin/templatetags/admin_list.py#L356

The function used there must handle __ segments, which my simple code changelist.model._meta.get_field doesn’t.

So changing this line should do it!

Exactly,I insert a try except with FieldDoesNotExist
,and useget_field_from_path
method

@FraCata00
Copy link
Contributor Author

tomorrow after work i will try to see again

@fabiocaccamo fabiocaccamo changed the title date_hierarchy on related fields in ForeignKey not work date_hierarchy on related fields in ForeignKey doesn't work. Jan 25, 2023
@fabiocaccamo
Copy link
Owner

@FraCata00 any update?

@FraCata00
Copy link
Contributor Author

@fabiocaccamo sorry Sir, I've been very busy with work and I haven't been able to keep up with it.. this week I'm trying to finish something

@fabiocaccamo
Copy link
Owner

@FraCata00 fixed in 0.25.0 version.

@github-project-automation github-project-automation bot moved this from Todo to Done in Open Source Apr 18, 2023
@FraCata00
Copy link
Contributor Author

@fabiocaccamo really good work!
my advice wasn't so wrong :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants