asifpy / django-crudbuilder

Generic CRUD implementation in Django
https://django-crudbuilder.readthedocs.org/en/latest/index.html
Apache License 2.0
193 stars 67 forks source link

Crudbuilder depends on the presence of an `id` field in the models #47

Closed polwel closed 6 years ago

polwel commented 7 years ago

Currently, crudbuilder depends on the presence of an id field in each of the models. Explicitely defining one's own primary key (with primary_key=True in the field definition) wreaks havoc. Instead, the code should reference the pk field, which always represents the primary key, either as set by the user, or id by default.

The first place that needs changing is mixins.BaseListViewMixin.get_queryset (in the return statement), The way it currently stands, it will crash django when the model does not have an id field.

There are more places where the code uses id, notably in tables.TableBuilder. Here a more sensible solution might be required though. Not sure if just replacing id by pk yields the correct behaviour in all cases.

asifpy commented 6 years ago

@polwel : I resolved this here https://github.com/asifpy/django-crudbuilder/commit/a17d09589ae0c9fdb6adda0faa673a797815ded1

I'm going to close this issue, you can reopen the same if you have further queries.