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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:13:49+00:00 2026-06-05T02:13:49+00:00

I am trying to create an edit form for my model. I did not

  • 0

I am trying to create an edit form for my model. I did not use a model form because depending on the model type, there are different forms that the user can use. (For example, one of the forms has a Tinymce widget, while the other doesn’t.)

Is there any way of setting the initial data of a form (not a ModelForm) using a model?

I tried the following but getting an error:

b = get_object_or_404(Business, user=request.user)
form = f(initial = b)

where f is a subclass of forms.Form

The error I am getting is AttributeError: 'Business' object has no attribute 'get'

  • 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-05T02:13:50+00:00Added an answer on June 5, 2026 at 2:13 am

    The initial data needs to be a dict (or at least have a dict-like interface, which a Django model does not have).

    You can construct a dict from your model using django.forms.models.model_to_dict:

    from django.forms.models import model_to_dict
    b_as_dict = model_to_dict(b)
    

    This is the same function Django’s built in ModelForm class uses to set its initial data, and while you’ve specified that you don’t want to use a ModelForm it may be more convenient to find some way of structuring your code that allows you to do so.

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

Sidebar

Related Questions

Am trying to simplify the create / edit view for a multi-model controller. User
I'm trying to create an element that contains a form so it can be
I am trying to create a form that serves as confirmation for the destroy
I'm trying create a gui using Tkinter that grabs a username and password and
Trying to create a regex pattern for email address check. That will allow a
I'm trying to override FOSUserBundle form Edit profile ; I have created the class
I'm trying to create a form using Cakephp's FormHelper class. The form needs to
The problem I'm having is I'm trying to create a form which passes the
I am currently trying to create a rating counter that has a up or
I'm trying to create two models, products and product_manufacturers so that I can pull

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.