Skip to content

FK ID field is not properly converted #106

@dmitry-saritasa

Description

@dmitry-saritasa

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions