On Thursday, 4 June 2020 16:25:09 UTC+1, OwlHoot wrote: > > > I believe the issue I have enquired about on the following Stack Exchange > page : > > > https://stackoverflow.com/questions/62162288/baffling-error-filtering-django-objects-of-derived-class-by-values-in-foreign-ke >
By adding some debug code in /usr/lib/python3.6/site-packages/django/db/backends/base/creation.py I have made some progress with this "bug" (which I am no longer convinced it is). The issue relates to a load of derived classes, as follows : class DataSet(models.Model) class PSessionDataSet(DataSet) ::: class FilteredDataSet(DataSet) class AggregateDataSet(DataSet) class SurveyRunDataSet(DataSet) class RestrictedDataSet(SurveyRunDataSet) These all have the same app_label value ("dataset") in their Meta class, and are thus in the same "group" of models. However, the debug logging line reveals that Django thinks all these classes share the same default manager (_default_manager), namely dataset.AggregateDataSet.objects: Model Default Manager ::: app.survey.models.grid.GridRow survey.GridRow.objects app.analysis.models.Analysis analysis.Analysis.objects app.analysis.report.models.AnalysisReport report.AnalysisReport.objects app.analysis.dataset.models.dataset.DataSet dataset.AggregateDataSet.objects app.analysis.dataset.models.survey_run.SurveyRunDataSet dataset.AggregateDataSet.objects app.analysis.dataset.models.filtered.FilteredDataSet dataset.AggregateDataSet.objects app.analysis.dataset.models.restricted.RestrictedDataSet dataset.AggregateDataSet.objects Now I know the documentation says the default manager is chosen as the first it happens to come across in the model group. But that sounds absolutely barking mad. Shouldn't each of these models have their own model-specific default manager, as all the models preceding the "dataset" models do in the above table?! Otherwise surely the manager will have trouble finding various columns/values in a model table other than the one on which it is based, which is exactly the error I am seeing! So now my problem becomes how to tweak each of these "dataset" models so their default managers will become as follows : Model Default Manager ::: app.survey.models.grid.GridRow survey.GridRow.objects app.analysis.models.Analysis analysis.Analysis.objects app.analysis.report.models.AnalysisReport report.AnalysisReport.objects app.analysis.dataset.models.dataset.DataSet dataset.DataSet.objects app.analysis.dataset.models.survey_run.SurveyRunDataSet dataset.SurveyRunDataSet.objects app.analysis.dataset.models.filtered.FilteredDataSet dataset.FilteredDataSet.objects app.analysis.dataset.models.restricted.RestrictedDataSet dataset.RestrictedDataSet.objects Would that just be a matter of adding lines as follows (typically in the FilteredDataSet class) : objects = FilteredDataSet.Manager() or does one need a more elaborate overriding of get_queryset() ? Any ideas gratefully received. ? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/961761ab-10d8-4f7d-bc24-961200f54e5co%40googlegroups.com.