>  if there are more than one packages with the same label?
>
> Two apps cannot have the same label. One of them must be relabeled as
> described
> in 
> https://docs.djangoproject.com/en/2.2/ref/applications/#django.apps.AppConfig.label.

OMG. Are in great advantage - those who can read.

>
> If a pluggable app wants to access its own app config even if it was
> relabeled, there's no direct API to do so, but it's a one-liner:
>
> from django.apps import apps
> app_name = "gdaps.frontend"
> app_config = [ac for ac in apps.get_app_configs() if ac.name ==
> app_name][0]
>
> This is pretty much how apps.is_installed(app_name) is implemented.
> There isn't a more efficient way to do this with the current
> implementation of django.apps.Apps.
>
> Perhaps the API of django.apps.Apps could be improved to facilitate
> such use cases. At first sight, there are several options to consider:
>
> - provide an apps.get_app_label(app_name) function that would do the
> translation from app_name to app_label
> - accept either an app_label (e.g. "admin") or an app_name (e.g.
> "django.contrib.admin") in APIs that currently only accept an app_label
> - etc.
>
> It's been five years since Django 1.7 was released with new app
> registry. During this time, I haven't seen app_label conflicts or
> relabeling causing big problems in practice. (The only vaguely related
> case I've ever seen was someone who copy-pasted an app under a
> different name. This changed both the app_label and the app_name, so
> even relying on the app_name would fail in that case.)
>
> I'd rather keep things simple here.
>
Yes, understood. Not a big problem here. From a novice POV, I dumbly
expected apps.get_app_config() to find the app when given a dotted name.
So IMHO this would be a good approach.

Apps.get_apps_config() itself does a search for the name, and returns a
message to the user ATM:

try:
    return self.app_configs[app_label]
except KeyError:
    message = "No installed app with label '%s'." % app_label
    for app_config in self.get_app_configs():
        if app_config.name == app_label:
            message += " Did you mean '%s'?" % app_config.label
            break

This could be a return statement too.

Just my 2c.

Christian

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/145544f6-9abd-c47c-b5c4-79fbf2ab0214%40nerdocs.at.

Attachment: pEpkey.asc
Description: application/pgp-keys

Reply via email to