9.2.5 Creating NewsLink Objects in a View with NewsLinkForm

In most respects, NewsLinkCreate is identical to our other object creation views. However, the post() method in NewsLinkCreate comes with an interesting quirk. Ignoring the difference in variable names (new_newslink instead of new_startup), we find ourselves unable to use redirect() in the same way as we previously did. That makes sense: Django convention only allows for this behavior because a model has a get_absolute_url() method. The problem is that our NewsLink class doesn’t! We could circumvent by redirecting to the page the NewsLink is displayed at: the Startup page, causing Django to call the get_absolute_url() method of the Startup object pointed to by our new NewsLink object. ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.