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

  • SEARCH
  • Home
  • 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 6894175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:44:58+00:00 2026-05-27T06:44:58+00:00

I have such views: def finish_creation(request, pre_id): pre_post = PrePost.objects.get(pk = pre_id) if pre_id

  • 0

I have such views:

def finish_creation(request, pre_id):
    pre_post = PrePost.objects.get(pk = pre_id)
    if pre_id == pre_post.id:
        this = Post.objects.create(
            author = pre_post.author,
            title = pre_post.title,
            text = pre_post.text
        )

        this.pswd = some_password
        this.save()
        pre_post.delete()
        return HttpResponseRedirect(this.get_absolute_url())

Explanation: unauthorized user (author) can write posts on site, but first creates some temporary pre_post in database and sends email to author with link in it to activate (transfer temporary pre_post to permanent post). After follow a link creates Post from PrePost elements, PrePost deletes from database and user automatically redirects to his publicated post.

But there is error: Pre_Post matching query does not exist.

But everything else is OK:

1) Post creates perfectly,

2) Pre_post deletes perfectly,

and only return HttpResponseRedirect(this.get_absolute_url()) doesn’t work…

However, error page refers on first line in views pre_post = PrePost.objects.get(pk = pre_id)

How could it be?

Thanks.

EDITED:

But when I didn’t delete pre_post everything worked fine as expected (except deletion of pre_post). What’s wrong with that delete()?

  • 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-27T06:44:59+00:00Added an answer on May 27, 2026 at 6:44 am

    This is really bad design to begin with. You shouldn’t be moving data from one table to another to publish it. Simply add a field to the one model. For example:

    class Post(models.Model):
        ...
        approved = models.BooleanField(default=False)
    

    Then, you can write a custom manager to pull only approved posts:

    class PostManager(models.Manager):
        def approved(self):
            return self.filter(approved=True)
    
    class Post(models.Model):
        ...
        objects = PostManager()
    

    Finally, in your views and templates, just use Post.objects.approved(), instead of Post.objects.all(). So only approved posts will ever be shown on site.

    You can then only show the approved field in your forms when the user is a superuser, or whatever other designation you want, and only they will be able to mark it as approved.

    You could also do this many other ways, such as a “Published” status that only superusers could set, etc., but this is the general idea.

    EDIT The problem with your current code is that there is always a possibility that an object won’t exist. You must account for that possibility by always wrapping calls to get in try...except blocks:

    try:
        pre_post = PrePost.objects.get(pk = pre_id)
    except PrePost.DoesNotExist:
        # Do something or...
        pass
    else:
        # object exists; you can do stuff with it here.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such a class: public class Cycle { public List<int> Edges { get;
I have such class public unsafe class EigenSolver { public double* aPtr {get; private
Code: # it's an ajax request, so parameters are passed via GET method def
I have models like this class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField() def
I have a simple ActionMailer class like this: class MyMailer < ActionMailer::Base def mail(from,
I have such view that handles user registration. After creating new user i want
I have such stuff in my django view: message = 'sometext' rating = 7
Suppose I'm implementing an MVP pattern and I have a view interface as such:
I have such html and css. <div class=selected> <div class=text>First</div> <div class=arrow>&nbsp;</div> </div> .selected
I have such code: <h:inputText id=input value=#{bean.input}> <f:convertNumber /> <rich:ajaxValidator event=onblur /> </h:inputText> I

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.