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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:06:00+00:00 2026-06-10T18:06:00+00:00

I am new to django and I am trying to use get_or_create model function

  • 0

I am new to django and I am trying to use get_or_create model function but I get an error even I have the attribute in my model

AttributeError at /professor/adicionar-compromisso
'tuple' object has no attribute 'dias'
Request Method: POST
Request URL:    http://localhost:8000/professor/adicionar-compromisso
Django Version: 1.4.1
Exception Type: AttributeError
Exception Value:    
'tuple' object has no attribute 'dias'
Exception Location: c:\htdocs\rpv\GerenDisponibilidade\professor\models.py in inserirCompromisso, line 63
Python Executable:  C:\Python27\python.exe
Python Version: 2.7.3
Python Path:    
['c:\\htdocs\\rpv\\GerenDisponibilidade',
 'C:\\Python27\\lib\\site-packages\\distribute-0.6.27-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\pip-1.1-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\sphinx-1.1.3-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\docutils-0.9.1-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\jinja2-2.6-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\pygments-1.5-py2.7.egg',
 'C:\\Windows\\system32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages',
 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info']
Server time:    Seg, 3 Set 2012 17:57:17 -0300

Model

class DiaSemana(models.Model):    
DIAS_CHOICES = (
                ("Seg", "Segunda-Feira"),
                ("Ter", "Terça-Feira"),
                ("Qua", "Quarta-Feira"),
                ("Qui", "Quinta-Feira"),
                ("Sex", "Sexta-Feira"),
                ("Sab", "Sábado"),
                ("Dom", "Domingo"),
                )           
dias = models.CharField(max_length=20, choices=DIAS_CHOICES) 

Here I am trying to search to check if there is existing value, otherwise create new and save

for diaSemana in diaSemanas:
        d = DiaSemana.objects.get_or_create(dias=diaSemana)
        d.dias = diaSemana;
        d.save() 
        c.save()
        c.diaSemana.add(d);

What’s wrong?

  • 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-10T18:06:02+00:00Added an answer on June 10, 2026 at 6:06 pm

    get_or_create does not just return the object:

    Returns a tuple of (object, created), where object is the retrieved or created object and created is a boolean specifying whether a new object was created.

    In your case d has been assigned this tuple instead of the object you expected, so you get the attribute error. You can fix your code by changing it to:

    d, created = DiaSemana.objects.get_or_create(dias=diaSemana)
    

    The following two lines look unnecessary to me. The get_or_create call above ensures that d.dias=diaSemana, so there’s no need to assign it again. There’s probably no need to call save either.

    d.dias = diaSemana;
    d.save()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Amazon's new SMTP service for SES with Django 1.3.1 but
I am new to django and trying to use django-messages to add inbox/compose/outbox/trash functionality
I am fairly new to Django and i am trying to use the builtin
i'm fairly new to django and just trying a couple simple experiments to get
I am new to Django and was trying this code in a tutorial. But
I am pretty new to Django and trying to use django-social-auth in my Django
I am new to Django, and I am trying to use django-friends in my
I'm new to Django, trying to process some forms. I have this form for
I'm trying to use the django-voting tutorial from this blog: http://new.justinlilly.com/blog/2008/nov/04/django-voting-a-brief-tutorial/ to get a
Hello I'm a newbie trying to use django to register some users, I have

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.