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

Fix chunkator when the primary key is a OneToOneField #19

Closed
zebuline opened this issue Jun 29, 2017 · 1 comment
Closed

Fix chunkator when the primary key is a OneToOneField #19

zebuline opened this issue Jun 29, 2017 · 1 comment

Comments

@zebuline
Copy link
Contributor

zebuline commented Jun 29, 2017

django-chunkator orders by pk.

But sometimes, you want to order by an explicit field.

For example:

class ModelA(models.Model):
    name = models.CharField(max_length=20)

    class Meta:
        ordering = ['name']


class ModelB(models.Model):
    modela = models.OneToOneField(ModelA, primary_key=True)

(with django 1.8 ?) when we write this queryset: ModelB.objects.order_by('pk'), it will in background order by modela__name.
We need to order the queryset by modela_id explicitely:

from chunkator import chunkator
for item in chunkator(ModelB.objects.all(), 200, order_by='modela_id'):
    do_something(item)

Edit: it is possible to fix this case without changing the API. See PR #20

zebuline added a commit that referenced this issue Jun 30, 2017
zebuline added a commit that referenced this issue Jun 30, 2017
zebuline added a commit that referenced this issue Jun 30, 2017
@zebuline zebuline changed the title Add the possibility to precise the field used for ordering Fix chunkator when the primary key is a OneToOneField Jun 30, 2017
zebuline added a commit that referenced this issue Jun 30, 2017
@brunobord
Copy link
Contributor

closed by #20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants