silentsokolov / django-admin-rangefilter

A Django app that lets you filter data by date range and numeric range in the admin UI
MIT License
721 stars 106 forks source link

Fixing double media loading issue #11

Closed marcinowski closed 6 years ago

marcinowski commented 7 years ago

Should fix https://github.com/silentsokolov/django-admin-rangefilter/issues/9 I've made this quick fix today, but can test it a bit more tomorrow though.

codecov-io commented 7 years ago

Codecov Report

Merging #11 into master will increase coverage by 0.1%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #11     +/-   ##
=========================================
+ Coverage   96.64%   96.75%   +0.1%     
=========================================
  Files           6        6             
  Lines         268      277      +9     
=========================================
+ Hits          259      268      +9     
  Misses          9        9
Impacted Files Coverage Δ
rangefilter/filter.py 93.06% <100%> (+0.67%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e45ec65...54eaf60. Read the comment docs.

silentsokolov commented 7 years ago

Good solution, but not works with two filtres.

Test on:

@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
    list_display = ('name', 'created_at')
    list_editable = ('created_at',)
    list_filter = (
        'name', ('created_at', DateRangeFilter), ('updated_at', DateRangeFilter),
    )
marcinowski commented 7 years ago

image Works for me just fine, I'm on Django 1.9.6.

Edit: Although I've modified the template a little, so that may have some impact. I can try checking it more over the weekend.

silentsokolov commented 7 years ago

Problem: 1510641997889

If there are no editable fields, the number of load scripts is not an problem.

marcinowski commented 6 years ago

image I'm back! :D I see that this issue is still not resolved, so I thought I'd get back to it. This time I've tested the solution on Django 2.0.5, the solution also seems a bit better, although I'm not 100% why this works. I've tested this on the following

from django.db import models
from django.contrib import admin

from rangefilter.filter import DateRangeFilter

class Post(models.Model):
    from_time = models.DateTimeField()
    to_time = models.DateTimeField()

class Comment(models.Model):
    from_time = models.DateField()
    to_time = models.DateField()

@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
    list_display = ('from_time', 'to_time')
    list_editable = ('from_time', 'to_time')
    list_display_links = None
    list_filter = (
        ('from_time', DateRangeFilter), ('to_time', DateRangeFilter)
    )

@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    list_display = ('from_time', 'to_time')
    list_editable = ('from_time', 'to_time')
    list_display_links = None
    list_filter = (
        ('from_time', DateRangeFilter), ('to_time', DateRangeFilter)
    )

Edit: I see that the coverage failed, if someone else can confirm manually this works, then I'll add some units

Edit2: of course it fails, it was too easy

marcinowski commented 6 years ago

Ok, I've found the issue myself, commenting out the list_editable removes the widget from filters, damn it

marcinowski commented 6 years ago

Ok, I think I've finally figured it out. Here's how it worked:

How it works now:

How it could work:

marcinowski commented 6 years ago

Tested on Chrome & Firefox on Django 2.0.5 (I can test on 1.8 tomorrow) with the following code:

from django.db import models
from django.contrib import admin

from rangefilter.filter import DateRangeFilter, DateTimeRangeFilter

class Post(models.Model):
    from_time = models.DateTimeField()
    to_time = models.DateTimeField()

class Comment(models.Model):
    from_time = models.DateField()
    to_time = models.DateField()

@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
    list_display = ('from_time', 'to_time')
    list_display_links = None
    list_filter = (
        ('from_time', DateTimeRangeFilter),
        ('to_time', DateTimeRangeFilter),
        ('to_time', DateTimeRangeFilter),
        ('to_time', DateTimeRangeFilter),
        ('to_time', DateTimeRangeFilter),
    )

@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    list_display = ('from_time', 'to_time')
    list_editable = ('from_time', 'to_time')
    list_display_links = None
    list_filter = (
        ('from_time', DateRangeFilter),
        ('to_time', DateRangeFilter),
        ('to_time', DateRangeFilter),
        ('to_time', DateRangeFilter),
        ('to_time', DateRangeFilter),
    )

AdminDateFilter included in editable image

Statics loaded: image

AdminDateFilter not included in editable image

silentsokolov commented 6 years ago

Unbelievable! It's work! 🎉 (1.8 / 2.0) @marcinowski thank you very much for the work done!