How can Django's ContentType uniquely describe an installed model when it only stores the last part of the App's import path in app_label?

StackOverflow https://stackoverflow.com/questions/15009835

  •  10-03-2022
  •  | 
  •  

Pergunta

The docs state that three fields (app_label, model, name) uniquely identify an installed model, while only storing the last part of the model's import path in app_label. How is this possible when you can have two models with the same name in different packages which happen to share the last module name, like:

1) coke.auth.User

2) pepsi.auth.User

?

Foi útil?

Solução

It doesn't matter: when you put 'auth' inside INSTALLED_APPS, only one Django app could be imported, it could be auth from either coke or pepsi, or other place containing auth, depending on their first occurring in sys.path.

Also, in DB, the unique constraint is applied to (app_label, model), the name is for description.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top