Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6757951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:42:59+00:00 2026-05-26T13:42:59+00:00

I am converting a WordPress site to a django one. I need to preserve

  • 0

I am converting a WordPress site to a django one. I need to preserve the url structure for old posts, but have a different structure for new posts. I’ve done this by creating the 2 urls, setting a date in settings.py, then setting the absolute url like so:

urls.py

url(r'^reviews/archives/(?P<pk>\d+)$', PostDetail.as_view(), name="oldpost_view"),

posts/urls.py

url(r'^(?P<slug>[-\w]+)$', PostDetail.as_view(), name="post_view"),

posts/models.py

@property        
def is_old_post(self):
    wp_date = settings.WP_ARCHIVE_DATE
    if self.post_date.date() < wp_date:
        return True
    # return False

@models.permalink    
def get_abs_url(self):
    if self.is_old_post:
        return ('oldpost_view', (), {
            'pk': self.id,
            }
        )
    else:
        return ('post_view', [str(self.url_slug)])

I am using one view for the 2 urls:

class PostDetail(DetailView):
    model = Post
    slug_field = 'url_slug'
    template_name = "posts/detail.html" 

This all works great. Now, what I need to is prevent new posts from being rendered by the oldpost_view url and vice versa. I know I can override the “get” and use reverse for this but how can I tell which url the request came from? What is the most efficient and DRY way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:43:00+00:00Added an answer on May 26, 2026 at 1:43 pm

    Based on Issac Kelly’s feedback I was able to solve my problem. Here’s the updated views:

    class PostDetail(DetailView):
        model = Post
        slug_field = 'post_name'
        template_name = "posts/detail.html"
    
    def OldPostView(request, pk):
        post_name = get_object_or_404(Post, pk=pk).post_name
        return redirect('post_view', slug=post_name, permanent=True)
    

    I also updated my models to utilize the “post_name” field that WordPress has, then simplified my permalink:

    @models.permalink    
    def get_abs_url(self):
        return ('post_view', [str(self.post_name)])
    

    Thanks Issac!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a new client that I am converting over to Drupal from Wordpress.
I have been asked to convert an entire site that is currently using wordpress
Converting an old vs2003 project to vs2010, and I've stumbled on one error: cannot
I have issue with url rewrite. I have a site example.com that has a
I am in the process of converting a site from Wordpress to a custom
Converting to ODB.NET from System.Data.OracleClient and need help converting my connection string. Here is
I'm converting an application to use Java 1.5 and have found the following method:
I'm converting an old app that records folder sizes on a daily basis. The
Converting another app from Rails 2 to Rails 3 - in one of my
Converting from Django, I'm used to doing something like this: {% if not var1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.