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

Types are not recognized in methods #79

Open
aliqb opened this issue Jan 3, 2024 · 0 comments
Open

Types are not recognized in methods #79

aliqb opened this issue Jan 3, 2024 · 0 comments

Comments

@aliqb
Copy link

aliqb commented Jan 3, 2024

If I have a integerField, the excel column will be number
but if I have a method in my model or serializer that return int, the excel column will be text
for ex:

class Statuses(models.IntegerChoices):
    SUPERVISOR = 0, _("awaiting supervisor's approval")
    EXPERT = 1, _("awaiting expert's approval")
    ACTIVE = 2, _("active")
    EXPIRE = 3, _("expired")
    EXTENDED = 4, _("extended")
    REJECT = -1, _("rejected")

    user = models.ForeignKey(User, on_delete=models.CASCADE)
    service = models.ForeignKey(Service, on_delete=models.CASCADE)
    status = models.IntegerField(choices=Statuses.choices, default=1)
    start_date = models.DateField(null=True, blank=True)
    duration = models.PositiveBigIntegerField(null=False)
    buy_date_time = models.DateTimeField(auto_now_add=True)
    paid_credit = models.PositiveIntegerField(null=True)

    @property
    def duration_hours(self):
        return self.duration // 3600000

    @property
    def total_price(self):
        return self.service.price * self.duration_hours

and a serializer with all fields, duration column will be number but total_price will be text
I seek in documentation but I didn't find a solution
use format for column data style does not work

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

1 participant