Sign Up

Talk Programming , Career, Mental Health, Talk Personal Finance ❤️‍ Post a query and receive responses ✅

Have an account? Sign In


Have an account? Sign In Now

Sign In

Post a query and receive responses. Ask anything, Ask Mitra ❤️‍

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

Sorry, you do not have permission to ask a question, 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

Ask Mitra

Ask Mitra Logo Ask Mitra Logo

Ask Mitra Navigation

  • Home
  • About Us
  • Find Jobs
  • Blogs
    • Add New Blog !
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Ask a Question
  • Home
  • All Categories
  • Find Jobs
  • Points and Swags
    • Badges and Points
    • Ask Mitra Swags
  • Blog
    • Add New Blog !
  • FAQs
  • Community Members 💓
  • About Us
  • Contact Us
Home| Questions|Q 59772
Next
Answered
Sudarshan_sap
Sudarshan_sap
Asked: June 9, 20222022-06-09T20:04:47+05:45 2022-06-09T20:04:47+05:45In: Programming

How to fix this ? Django error ?

girlshostel=GirlsHostel.objects.create(owner, hostel, address,phone,teliphone,
facilities,images)
girlshostel.save()

error:

'function' object has no attribute 'objects'
bugsDjangoerrors
  • 0
  • 7 7 Answers
  • 72 Views
  • 0 Followers
  • 0
Share
  • Facebook

    Related Questions

    • Django Logs
    • Moving On
    • Deprecated Error On The Site
    • Anyone who has added nepali BS date in django
    • How to crack a Python or Django interview ?

    You must login to add an answer.


    Forgot Password?

    Need An Account, Sign Up Here

    7 Answers

    • Voted
    • Oldest
    • Recent
    • Random
    1. [Deleted User]
      2022-06-09T22:44:00+05:45Added an answer on June 9, 2022 at 10:44 pm
      This answer was edited.

      the  GirlsHostel is what?
      you imported from model.py?

      model class ho bhani .objects chai hunai parcha.. so confirm once..

      you could have directly done this

       from . import models

      girlshostel = models.GirlsHostel.objects.......

      include screenshots of errors and that portion of code in reply.. because i have not enough info to assist you 

      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
      • [Deleted User]
        2022-06-09T22:47:17+05:45Replied to answer on June 9, 2022 at 10:47 pm

        what a code highlighter code katai cha ani highlighting katai cha.. already edited more than 3 times fixing that

        • 0
        • Share
          Share
          • Share on Facebook
          • Share on Twitter
          • Share on LinkedIn
          • Share on WhatsApp
        • Sudarshan_sap
          2022-06-09T23:00:26+05:45Replied to answer on June 9, 2022 at 11:00 pm
          Another error :'
          
          
          GirlsHostel() got an unexpected keyword argument 'owner'
          
          girlshostel=GirlsHostel(owner=owner, hostel=hostel, address=address, phone=phone,
          teliphone=teliphone,
          faciliti=facilities, images=images)
          • 0
          • Share
            Share
            • Share on Facebook
            • Share on Twitter
            • Share on LinkedIn
            • Share on WhatsApp
          • [Deleted User]
            2022-06-10T00:15:38+05:45Replied to answer on June 10, 2022 at 12:15 am

            you dont have owner field in your GirlsHostel Model

            • 0
            • Share
              Share
              • Share on Facebook
              • Share on Twitter
              • Share on LinkedIn
              • Share on WhatsApp
            • Sudarshan_sap
              2022-06-10T12:12:18+05:45Replied to answer on June 10, 2022 at 12:12 pm

              models.py

              class GirlsHostel(models.Model):
              owner = models.OneToOneField(User,on_delete=models.CASCADE,primary_key=True)
              hostel=models.CharField(max_length=70)
              address=models.CharField(max_length=70)
              phone=models.IntegerField()
              teliphone=models.IntegerField()
              facilities=models.TextField(max_length=2000)
              images=models.ImageField(upload_to=”images”,default=”xd”)

              views.py

              def GirlsHostel(request):
              if request.user.is_authenticated:
              if request.method==”POST”:
              owner=request.POST[‘Owner’]
              hostel=request.POST[‘Hostel’]
              address=request.POST[‘Address’]
              phone=request.POST[‘Phone’]
              teliphone=request.POST[‘Teliphone’]
              facilities=request.POST[‘Facilities’]
              images = request.FILES[‘Images’]
              girlshostel=GirlsHostel(owner=owner, hostel=hostel, address=address, phone=phone,
              teliphone=teliphone,
              faciliti=facilities, images=images)
              girlshostel.save()

              return redirect(‘/home’)
              else:
              return render(request,’post.html’)
              else:
              return redirect(‘/login’)

              • 0
              • Share
                Share
                • Share on Facebook
                • Share on Twitter
                • Share on LinkedIn
                • Share on WhatsApp
    2. Best Answer
      THE BIG OCEAN Explainer
      2022-06-10T14:52:59+05:45Added an answer on June 10, 2022 at 2:52 pm

      Always write python class name in PascalCase, For example, “GirlsHostel” and function name in lower case with separated by underscore like this “def girls_hostel(request):”.

      And remember that naming convention is also important in every language which makes your code easily readable and understandable by the machine itself. You wrote the same name for the model and function which is causing a problem because the Model name and view name shouldn’t be the same in Django.

       

      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
      • Sudarshan_sap
        2022-06-10T16:33:05+05:45Replied to answer on June 10, 2022 at 4:33 pm

        Thank you so much Sir ! Bug is fix now .

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

    Sidebar

    Ask A Question

    Your Favourite Topics

    • Announcements
    • Blockchain
    • Books

        • —Non Tech Books
        • —technical books
    • Business and Entrepreneurship
    • Careers
    • College
    • Content and Blog
    • CyberSecurity
    • Design and Arts
    • Devices and Gadgets
    • Digital Marketing
    • Entertainment

        • —Movies-Series-TV
        • —Music
        • —Sports
    • Events
    • For Admins only.
    • Health

        • —Fitness
    • Money

        • —Personal Finance
        • —Stock Market
    • Operating System

        • —linux
        • —windows
    • Other
    • Paid Internship
    • Programming

        • —AI/ML
        • —APIs
        • —C & C#
        • —Django
        • —Flutter
        • —Go
        • —HTML&CSS
        • —Java
        • —JavaScript
        • —Mobile Apps Development
        • —Node Js
        • —NoSQL
        • —Php
        • —Python
        • —React JS
        • —SQL

    Stats

    • Questions 1k
    • Answers 10k
    • Best Answers 394
    • Users 2k

    Top 6 Members This Month

    Vicky

    Vicky

    • 0 Questions
    • 78 Points
    Sensei
    puppet

    puppet

    • 0 Questions
    • 23 Points
    Beginner
    wtfixair

    wtfixair

    • 0 Questions
    • 22 Points
    Beginner
    Dhanmaya

    Dhanmaya

    • 0 Questions
    • 20 Points
    Beginner
    Riyesh

    Riyesh

    • 0 Questions
    • 20 Points
    Beginner
    pranitkarki

    pranitkarki

    • 0 Questions
    • 20 Points
    Beginner

    Trending Tags

    blockchain c++ career coding College cybersecurity Django Flutter help html javascript laptop laravel linux poll Programming python question react web web development wordpress
    • Popular
    • Answers
    • Rounak Agrawal

      Ask Mitra Udemy Courses Giveaway

      • 76 Answers
    • Subedi Bibek

      The Complete JavaScript Course 2022: From Zero to Expert! Udemy ...

      • 73 Answers
    • Subedi Bibek

      Mega Giveaway at askmitra.com 🔥

      • 69 Answers
    • Sandeep Poudel
      Sandeep Poudel added an answer SOLVED: It was due to unfinished SSL certificate installation January 27, 2023 at 7:11 pm
    • Aashutosh_k
      Aashutosh_k added an answer Software piracy protection system Fingerprint voting system Stock price prediction… January 26, 2023 at 7:37 pm
    • Sangam AKA Ronnie
      Sangam AKA Ronnie added an answer Did you miss my video. https://youtu.be/Wo0NxEivd7A watch at end to… January 24, 2023 at 9:13 pm

    Related Questions

    • Hi I am doing my major project using CNN. Can ...

      • 0 Answers
    • Can you guys suggest some projects for my final year ...

      • 1 Answer
    • Low end emulator of android studio

      • 2 Answers
    • Can someone briefly explain me difference between Hot reload and ...

      • 2 Answers
    • Hello guys, ma chai bachelor pass out ho ani I ...

      • 1 Answer

    Explore

    • Home
    • Trending Category
      • Programming
      • Web Development
      • —Mobile Apps Development
      • —Stock Market
      • Business and Entrepreneurship
      • Blockchain
      • College
      • —Personal Finance
      • —HTML&CSS
      • —JavaScript
      • —Python
      • —React JS
      • —Node Js
      • —C & C#
      • Content and Blog
      • Careers
    • All Categories
      • Go to All Categories
      • Health
      • —Go
      • —Flutter
      • Digital Marketing
      • —APIs
      • Devices and Gadgets
    • Find Job and Internships
    • Points and Swags
      • Badges and Points
      • Ask Mitra Swags
    • All Blogs
      • Add New Blog !
    • FAQs
    • Community Members 💓
    • Questions
      • Un Answered
      • New Questions
      • Most Seen Questions
      • Most Answered
      • Trending Questions
    • Tags

    Footer

    Ask Mitra

    Ask Mitra

    Ask Mitra is a social question and answer engine that will assist you in forming a community and connecting with others. Talk about programming, your career, your mental health, and your personal finances. ❤️‍ Post a query and receive responses ✅

    Quick Navigation

    • Ask a Question
    • Home
    • All Categories
    • Find Jobs
    • Points and Swags
      • Badges and Points
      • Ask Mitra Swags
    • Blog
      • Add New Blog !
    • FAQs
    • Community Members 💓
    • About Us
    • Contact Us

    Legal Stuff

    • Terms of use and policy