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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:47:31+00:00 2026-06-16T14:47:31+00:00

I want to get an object value from a model. After trying the get()

  • 0

I want to get an object value from a model. After trying the get() method, I’ve been unable to make it work.And I’m getting the below error. I have a page that display the name of a place to users, so if a user see a place he likes, he will go ahead and fill the form.And in the form, I want to get the name of the place automatically from another model, I don’t want users to fill the name of the place. Below are my codes

       NameError at /welcome/

       global name 'name' is not defined

Models

 class Fin(models.Model):
      user=models.ForeignKey(User)
      name=models.CharField(max_length=100)

      def __unicode__(self):
          return self.user


 class Place(models.Model):
      user=models.ForeignKey(User)
      mall=models.ForeignKey(Fin)
      full_name=models.CharField(max_length=100)
      e_mail=models.EmailField(max_length=100)
      phone_no=models.CharField(max_length=100)
      pub_date=models.DateTimeField()

      def __unicode__(self):
          return self.full_name
      class Meta:
         ordering=['-pub_date']

  class PlaceForm(ModelForm):
       class Meta:
         model=Place
         fields=('full_name','e_mail','phone_no')
         exclude=('user','pub_date','mall')

Views:

   def place_me(request):
       if request.method=="POST":
          form=PlaceForm(request.POST)
          if form.is_valid():
             data=form.cleaned_data
             newbooks=Place(
                 user=request.user,
                 pub_date=datetime.datetime.now(),
                 mall=Fin.objects.get(name),
                 full_name=data['full_name'],
                 e_mail=data['e_mail'],
                 phone_no=data['phone_no'])
             newbooks.save()
             return HttpResponse('Thanks for choosing themall, we will contact you as soon as possible. Go grab a beer :)')
         else:
            return HttpResponse('Some fields are not filled correctly')
     else:
        return render_to_response('buuk.html',{'PlaceForm':PlaceForm},context_instance=RequestContext(request))
  • 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-16T14:47:32+00:00Added an answer on June 16, 2026 at 2:47 pm

    This line mall=Fin.objects.get(name) you have not declared the name variable any where in your view place_me, hence it is undefined.

    Also the way you are passing argument in .get is wrong, it has to be like this:

    mall=Fin.objects.get(name='any name')
    # or you can do
    mall=Fin.objects.get(user=request.user)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get an object from the database if it already exists (based
I want to get an object by a static factory method, such as Person
If I have Model.objects.all() I want to get only one object for any content_object=foo,
I want to get the value of a parameter in a sqlalchemy query object
I'm trying to add an object created from Entity Data Model classes. I have
I want to *pre_init* order value of my model as increamented value from other
i want to get the height property of a object: $('.selector img').each(function(index,e){ thisImage =
I want to get a list of inner objects of a scala object. Sample
Assume I have an enumerable object enum and now I want to get the
I have a map that represents a DB object. I want to get 'well

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.