Opened 21 months ago

Closed 21 months ago

Last modified 21 months ago

#34474 closed Bug (invalid)

Django apps registry returns the wrong models

Reported by: Dimitris Kougioumtzis Owned by: nobody
Component: Uncategorized Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When i want to get the models for the app sites it returns the wrong models

def get_models(request):
    app = request.GET.get('app')
    models = []
    amodels = apps.get_models(app)
    for model in amodels:
        models.append(model.__name__)
    return JsonResponse({"models":models})

when i call the function with request parameters sites it returns models from the admin app

Change History (6)

comment:1 by Tim Graham, 21 months ago

Hi, the problem and how to reproduce it isn't clear to me. Can you elaborate?

in reply to:  1 comment:2 by Dimitris Kougioumtzis, 21 months ago

Replying to Tim Graham:

Hi, the problem and how to reproduce it isn't clear to me. Can you elaborate?

Hello Tim

In the above function i pass a request get parameter called (app) and i want to return the models for the specific app,

For example when i pass the app name sites i want to return the Site model

but the function returns models from auth app

comment:3 by Tim Graham, 21 months ago

Resolution: invalid
Status: newclosed

This function doesn't seem to be part of Django. Please see TicketClosingReasons/UseSupportChannels if you need help debugging your code. Use this ticket tracker to report a bug in Django, explaining why Django is at fault and providing sufficient code to reproduce the problem.

in reply to:  3 comment:4 by Dimitris Kougioumtzis, 21 months ago

Replying to Tim Graham:

This function doesn't seem to be part of Django. Please see TicketClosingReasons/UseSupportChannels if you need help debugging your code. Use this ticket tracker to report a bug in Django, explaining why Django is at fault and providing sufficient code to reproduce the problem.

the result of the above function for the app django.contrib.messages

django.contrib.messages [<class 'django.contrib.admin.models.LogEntry'>, <class 'django.contrib.sites.models.Site'>, <class 'django.contrib.flatpages.models.FlatPage_sites'>, <class 'django.contrib.flatpages.models.FlatPage'>, <class 'django.contrib.auth.models.Permission'>, <class 'django.contrib.auth.models.Group_permissions'>, <class 'django.contrib.auth.models.Group'>, <class 'django.contrib.auth.models.User_groups'>, <class 'django.contrib.auth.models.User_user_permissions'>, <class 'django.contrib.auth.models.User'>, <class 'django.contrib.contenttypes.models.ContentType'>, <class 'django.contrib.sessions.models.Session'>, <class 'rest_framework.authtoken.models.Token'>, <class 'rest_framework.authtoken.models.TokenProxy'>]

so is it correct for the app django.contrib.messages it return that models ?

comment:5 by Tim Graham, 21 months ago

The signature for: apps.get_models(include_auto_created=False, include_swapped=False)

The get_models() function in this ticket's description is incorrectly providing app as the first argument.

in reply to:  5 comment:6 by Dimitris Kougioumtzis, 21 months ago

Replying to Tim Graham:

The signature for: apps.get_models(include_auto_created=False, include_swapped=False)

The get_models() function in this ticket's description is incorrectly providing app as the first argument.

Thanks Tim i fixed it

Note: See TracTickets for help on using tickets.
Back to Top