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

foreign_field option breaks for models.OneToOneRel #127

Open
Eric-RemoteNC opened this issue Feb 26, 2024 · 0 comments
Open

foreign_field option breaks for models.OneToOneRel #127

Eric-RemoteNC opened this issue Feb 26, 2024 · 0 comments

Comments

@Eric-RemoteNC
Copy link

Eric-RemoteNC commented Feb 26, 2024

column_defs 's foreign_field option breaks for models.OneToOneRel when there is no related_model linking to this obj.
Maybe in columns.py, get_foreign_value has to check if current_path_item is one of the OneToOneRel's name.

To be more specific, here is my test code:

models.py

class ModelA(MyModel):

    class Meta:
        ordering = ['pk']


class ModelB(MyModel):
    modelA = models.OneToOneField(ModelA,
                                  related_name='modelB',
                                  on_delete=models.CASCADE,
                                  null=True, blank=True,
                                  verbose_name="ModelA")

    class Meta:
        ordering = ['pk']

ajax_datatable_views.py

class ModelA_AjaxDatatableView(AjaxDatatableView):
    model = ModelA
    column_defs = [
        {
            "title": "id",
            "name": "id",
        },
        {
            "title": "modelB",
            "name": "modelB__id",
            "foreign_field": "modelB__id",
        }
    ]

p.s. Thank you for this fantastic project

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