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 8305269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:04:30+00:00 2026-06-08T18:04:30+00:00

Update: The solution can be found as a separate answer I am making a

  • 0

Update: The solution can be found as a separate answer

I am making a Django form to allow users to add tvshows to my db. To do this I have a Tvshow model, a TvshowModelForm and I use the generic class-based views CreateTvshowView/UpdateTvshowView to generate the form.

Now comes my problem: lets say a user wants to add a show to the db, e.g. Game of Thrones. If a show by this title already exists, I want to prompt the user for confirmation that this is indeed a different show than the one in the db, and if no similar show exists I want to commit it to the db. How do I best handle this confirmation?

Some of my experiments are shown in the code below, but maybe I am going about this the wrong way. The base of my solution is to include a hidden field force, which should be set to 1 if the user gets prompted if he is sure he wants to commit this data, so that I can read out whether this thing is 1 to decide whether the user clicked submit again, thereby telling me that he wants to store it.

I would love to hear what you guy’s think on how to solve this.

views.py

class TvshowModelForm(forms.ModelForm):
    force = forms.CharField(required=False, initial=0)
    def __init__(self, *args, **kwargs):
        super(TvshowModelForm, self).__init__(*args, **kwargs)

    class Meta:
        model = Tvshow
        exclude = ('user')

class UpdateTvshowView(UpdateView):
    form_class = TvshowModelForm
    model = Tvshow
    template_name = "tvshow_form.html"

    #Only the user who added it should be allowed to edit
    def form_valid(self, form):
        self.object = form.save(commit=False)
        #Check for duplicates and similar results, raise an error/warning if one is found     
        dup_list = get_object_duplicates(Tvshow, title = self.object.title)
        if dup_list:
            messages.add_message(self.request, messages.WARNING, 
'A tv show with this name already exists. Are you sure this is not the same one? Click submit again once you\'re sure this is new content'
               )
#            Experiment 1, I don't know why this doesn't work
#            form.fields['force'] = forms.CharField(required=False, initial=1)

#            Experiment 2, does not work: cleaned_data is not used to generate the new form
#            if form.is_valid():
#                form.cleaned_data['force'] = 1

#            Experiment 3, does not work: querydict is immutable
#            form.data['force'] = u'1'

        if self.object.user != self.request.user:
            messages.add_message(self.request, messages.ERROR, 'Only the user who added this content is allowed to edit it.')

        if not messages.get_messages(self.request):
            return super(UpdateTvshowView, self).form_valid(form)
        else:
            return super(UpdateTvshowView, self).form_invalid(form)
  • 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-06-08T18:04:31+00:00Added an answer on June 8, 2026 at 6:04 pm

    I will post it as an answer. In your form’s clean method you can validate user’s data in the way you want. It might look like that:

    def clean(self):
        # check if 'force' checkbox is not set on the form
        if not self.cleaned_data.get('force'):
            dup_list = get_object_duplicates(Tvshow, title = self.object.title)
            if dup_list:
                raise forms.ValidationError("A tv show with this name already exists. "
                                            "Are you sure this is not the same one? "
                                            "Click submit again once you're sure this "
                                            "is new content")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: A sample project reproducing this bug can be found here at Microsoft Connect
Update Solution Found See Bottom of post if interested Seems simple enough and for
Update: I've added an answer that describes my final solution (hint: the single Expr
NOTE: I added my new solution at the UPDATE answer below. I try to
Update: This question was an epic failure, but here's the working solution. It's based
Possible Duplicate: SQL ORDER BY total within GROUP BY UPDATE: I've found my solution,
UPDATE - Cause found! ... please read below & suggest the solution: While creating
I've been searching this web-site and other sources for an answer, but haven't found
I am not interested in any auto update solution, such as ClickOnce or the
[UPDATE] the clean goal runs smoothely all over the projects of the solution, the

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.