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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:25:11+00:00 2026-05-31T07:25:11+00:00

I m using generic view to update object. I m using form : class

  • 0

I m using generic view to update object.

I m using form :

class VehiPrepaClientForm(ModelForm):




class Meta:
    model = VehiPrepa
    fields = ('date_dem_prepa','carburant','ty_carburant')



def clean(self):
    cleaned_data = self.cleaned_data
    data = self.cleaned_data['date_dem_prepa']

    vehiprepa = get_object_or_404(VehiPrepa,pk=object_id)
    if data :

        vehiprepa.demande_prepa = 1
        vehiprepa.save()
        date_in = vehiprepa.date_in
        delta = data - date_in
        date_dem = date_in + delta 
        if delta.days < 2 :
            raise forms.ValidationError("Veuillez entrez une date au dela du : %s" %(date_dem) )

        if data.weekday()>= 5 :

            raise forms.ValidationError("La date choisie n'est pas valide, cela tombe un weekend")    

        #test si date demande sup a date_in et si pas samedi, ni dimanche, et si pas plus 32 vehi ce jour la



    return cleaned_data

I m using this generic view :

def vehiprepa_update (request, vehiprepa_id):

user= request.user

login = user.username
vehiprepa = get_object_or_404(VehiPrepa,pk=vehiprepa_id)

url_template_base = "base_client_washtest.html"


    response = create_update.update_object(
            request,
            form_class = VehiPrepaClientForm, 
            object_id = vehiprepa_id,
            post_save_redirect = "/washtest/vehiprepa_list/0/",
            template_name = 'washtest/vehiprepa_update.html',
            template_object_name = 'object',
            extra_context = {"url_template_base":url_template_base,"login":login,"vehiprepa":vehiprepa},)

return response

But i have an error, because object_id on my form is not known….
How can i get my request object id to use in my form clean ?

Thx

EDIT : HEre the error :

global name ‘object_id’ is not defined

  • 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-31T07:25:12+00:00Added an answer on May 31, 2026 at 7:25 am

    Your error comes from this line:

    vehiprepa = get_object_or_404(VehiPrepa,pk=object_id)

    In your model form, you don’t have a object_id.

    To solve this problem, refer to the documentation; which states:

    Also, a model form instance bound to a model object will contain a
    self.instance attribute that gives model form methods access to that
    specific model instance.

    From that we understand that the bound instance is in self.instance. So, in your model form you need

    vehiprepa = self.instance

    instead of the get_object_or_404 line.

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

Sidebar

Related Questions

I using Django and a generic view django.views.generic.create_update.create_object I have a model form wich
I'm using the generic view django.contrib.auth.views.password_reset for the password reset form. In principle, it
I am using a Generic Class as a Response Data Contract. All is good
I am trying to update a complex model in a single view. I am
I'm using ajax and trying to pass the Model back, which is a generic
I am using Django generic View but when i type /book/edit/9/ Then it says
In my views I'm using a generic type for the Model, ItemModel<T> . This
I made in my web a menu using generic_view - simple 'django.views.generic.list_detail.object_list' in urls.py
I am using generic code (from the iOS Fireworks demo) in a slightly changed
About five years ago I started using Generic lookup Tables for applications I was

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.