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

FK ID field is not properly converted #106

Open
dmitry-saritasa opened this issue Oct 16, 2018 · 1 comment
Open

FK ID field is not properly converted #106

dmitry-saritasa opened this issue Oct 16, 2018 · 1 comment

Comments

@dmitry-saritasa
Copy link

When I'm instructing queryset to be converted to Pandas dataframe with

to_dataframe(['id', 'employee', 'employee_id'],index='job_date')

In df's column employee_id I have the same value as employee.


In [97]: df = Job.objects.all().order_by('-id')[:100].to_dataframe(['id', 'employee', 'employee_id'],index='job_date')

In [98]: df
Out[98]: 
                id   employee       employee_id
job_date                                                                        
2017-07-18  918187   [email protected]      [email protected]
2017-07-18  918186   [email protected]      [email protected]
2017-07-18  918185   [email protected]     [email protected]
2017-07-18  918184   [email protected]      [email protected]

In [100]: Job.objects.last().employee
Out[100]: <Employee: [email protected]>

In [101]: Job.objects.last().employee_id
Out[101]: 115

I have a str method in Job class

class Job(SyncTimeStampedModel, BaseModel):
    employee = models.ForeignKey(
        to='users.Employee',
        on_delete=models.PROTECT,
        related_name='jobs',
        verbose_name=_('Employee'),
    )
class Employee(TimeStampedModel, BaseModel):
    def __str__(self):
        return self.user.username

Question

So how to export the ID into dataframe?

@mick88
Copy link

mick88 commented Nov 18, 2021

I have the same problem. The workaround I'm using is employee__id instead of employee_id

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