djangopackages-zz / djangopackages

Django Packages - a place to review Django apps, frameworks, and projects.
http://djangopackages.com
MIT License
53 stars 40 forks source link

fix to issue 59 #92

Closed bryanweingarten closed 13 years ago

bryanweingarten commented 13 years ago

Added management command fix_grid_element to dedup rows. The command is called it fix_blah to make it generic so in the future more than just deduping can be done to this table.

Also, it was verified that the production code was correct and can't add a duplicate entry as written. And a duplicate cannot be added with the admin UI. Therefore, these duplicate rows must have occurred prior to the current code, or entered directly in the database (maybe with some script).

It was verified that after fix_grid_element is run, clicking on the cell specified in issue 59 behaves correctly and allows the user to edit the grid element instead of causing a traceback.

bryanweingarten commented 13 years ago

You can also use the following Django "as-designed" model constructs to dedup if you don't like the original code... but it think it's harder to read.

e = Element.objects.values('feature__id', 'grid_package__id').order_by().annotate(num_feed=Count('feature__id'), num_grid_pack=Count('grid_package__id')).filter(num_feed__gt=1)

pydanny commented 13 years ago

Wahoo!