I’m trying to send an email to a user when a new model instance is saved and I want the email to include a link to the admin page for that model instance. Is there a way to get the correct URL? I figure Django must have that information stored somewhere.
Share
This Django snippet should do:
The
selfrefers to the parent model class, i.e.self.idrefers to the object’s instanceid. You can also set it as apropertyon the model by sticking the@propertydecorator on top of the method signature.EDIT: The answer by Chris Pratt below saves a DB query over the
ContentTypetable. My answer still “works”, and is less dependent on the Django modelinstance._metainternals. FYI.