These are chat archives for django/django

19th
Apr 2017
Fabian
@fabiand93
Apr 19 2017 18:55 UTC
hello
I'm trying to remove some duplicate data on my db
def duplicates():
    plans_rebalances=PlanRebalance.objects.filter(rebalance_date="2016-04-29").order_by('id')
    for rebalance in plans_rebalances:
        repeated = PlanRebalance.objects.filter(rebalance_date="2016-04-29", real=False, plan=rebalance.plan).annotate(
            Count('plan')).filter(plan__count__gt=1)
        while repeated.plan__count > 1:
            print(repeated)
            first, rest = repeated[0], repeated[1:]
            rest.remove()
but I get this error
'QuerySet' object has no attribute 'plan__count'
Cristian Samaniego
@chrisRubiano
Apr 19 2017 19:00 UTC
i think it is because repeated has the entire queryset
maybe you should do a loop for that like for plan_rebalance in repeated:
Steven Liao
@Penspinner
Apr 19 2017 19:02 UTC
^
Fabian
@fabiand93
Apr 19 2017 19:08 UTC
i'll test it
Cristian Samaniego
@chrisRubiano
Apr 19 2017 19:19 UTC
https://docs.djangoproject.com/es/1.10/ref/models/querysets/#select-related i think this will also help you with performance
cs89gr
@cs89gr
Apr 19 2017 19:24 UTC
hello is here someone ?
Philip Eckert
@pae4557
Apr 19 2017 20:10 UTC
Okay so when I try to run python -Wall manage.py test to see what warnings I need to deal with to upgrade, I get thousands of ImportWarnings and can't read anything else. Is there a way to log everything or filter out those specific warnings?
stemcc
@stemcc
Apr 19 2017 23:15 UTC
Using a package as a library vs using it as an app -- what's the difference? Django-organizations says it can be used as a library -- I think this means that I need to manually bring in its various base and abstract base classes into my own project's models. Am I understanding that right?