I’m currently trying to add a link to an object in the admin interface in a view.
The Documentation on reversing admin URLs says the following should work
'RescueOrganization' object has no attribute 'app_label'
I know that I need an app label
The opts variable can be any object which has an app_label and model_name attributes and is usually supplied by the admin views for the current model.
However I don’t understand why RescueOrganizations has no app label? It’s in my normal models.py and just as a sanity check I had a look in the DB and the table is called fellchensammlung_rescueorganization.
I also tried setting the app label, without any effect.
Any idea what could cause this?
If you want to check out the source here are some links (but I’d also be happy to provide the relevant snippets)
While I can’t verify everything here, I do see that:
is constructed incorrectly.
The org.id needs to be part of the url tag to pass as a parameter to the ‘change’ url.
Notice the difference in the location of the parameter between what you have above and the sample in the docs: <a href="{% url opts|admin_urlname:'delete' user.pk %}">Delete this user</a>
Also, the models themselves do not have app_label and model_name attributes. They’re exposed in the _meta attribute of the model. This means you should use something like {% url org._meta|admin_urlname:'change' ...
Also, you do not have a model named rescue_org. For the purpose of the reverse function, I would expect you to need to use 'fellchensammlung_rescueorganization_change'
You are absolutely right, however I also tried this and it results in the same error
NoReverseMatch at /tierschutzorganisationen/2900/
Reverse for 'fellchensammlung_rescueorganization_change' not found. 'fellchensammlung_rescueorganization_change' is not a valid view function or pattern name.
Sorry for the mess, I tried so many things and pasted the wrong attempts in my initial post.
This is a slight difference to what you proposed as I can’t access ._meta in a template (Variables and attributes may not begin with underscores: 'org._meta')