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 support django lazy property #76

Merged
merged 1 commit into from
Jun 23, 2023

Conversation

BilityLeu
Copy link
Contributor

Thank you for developing such an excellent plugin. I have found that when encountering django lazy loading, an error will be reported. The following example can reproduce this problem:

from django.db import models
from django.utils.translation import gettext_lazy as _
class MyModel(models.Model):
    STATUS_CHOICES = (
        ('Created', _('Created')),
        ('Processing', _('Processing')),
        ('Finished', _('Finished')),
    )
    status = models.CharField(choices=STATUS_CHOICES)
    ...


from rest_framework import serializers
class MySerializers(serializers.ModelSerializer):
    status_display = serializers.CharField(source='get_status_display')

    class Meta:
        model = MyModel
        fields = ('status', 'status_display')

Only use gettext_ Lazy only has this issue, and gettext does not. I have analyzed that the reason for the problem is that lazy returned a obj of __ proxy__(a subclass of Promise) type , which is not a common data type.

I tried to fix this issue and submitted a merge request, which may not be elegant, but at least it works.

@FlipperPA FlipperPA merged commit f3ac655 into wharton:main Jun 23, 2023
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

Successfully merging this pull request may close these issues.

None yet

2 participants