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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:54:43+00:00 2026-06-14T12:54:43+00:00

Something that has worked perfectyle until recently has stopped working. A model that has

  • 0

Something that has worked perfectyle until recently has stopped working. A model that has a foreignkey to another object isn’t editable as expected in the standard django admin. The problem is this: ForeignKeys to some model aren’t editable in de admin interface, though they should be, although a label does appear in the admin page.
It looks like this: Django interface edit-page for the question-model

The HTML-code for the bit where the foreignkey to the Story-model should be edited:

<div class="form-row field-story">
        <div>
            <label for="id_story" class="required">Story:</label>           
        </div>
</div>

2 relevant models with their respective unicode defs:

class Question(models.Model):
    question = models.CharField(max_length = 200)#the Actual question
    correct_answer = models.ForeignKey(Answer, verbose_name = 'Correct Answer', related_name = 'Correct answer')
    incorrect_answers = models.ManyToManyField(Answer, verbose_name = 'Distractor options', related_name = 'Incorrect answers')
    story = models.ForeignKey(Story)

    def __unicode__(self):
        try:
             return self.question.decode('latin-1') + '(%i)'%(self.id)
        except:
            return str(self.id)


class Story(models.Model):
    class Meta:
        verbose_name_plural = 'Stories'

    author = models.ForeignKey(User, blank = True, null = True, on_delete = models.SET_NULL, editable = False)
    name = models.CharField(max_length = 150, verbose_name = 'Name/Summary')
    story = models.TextField(verbose_name = 'Story', max_length = 13 * 54)#the actual story
    publish = models.BooleanField(default = False, help_text = 'If this is published, it will be uneditable.')
    date_added = models.DateTimeField (auto_now_add = True, editable = False)#date of reply
    ready = models.BooleanField(default = False, help_text = 'Whether the author thinks this is ready')
    erf = models.CharField(max_length = 20, verbose_name = 'ERF label', editable = False, blank  = True, null = True)

    def __unicode__(self):
        try:
            return "'"+self.name.encode( 'latin-1') + "'"
        except:
            return "Story with unicode name or something: %i" %(self.id)

In admin.py:

admin.site.register(Question, )

Looking at what works and what doesn’t, I’m beginning to feel it has got something to do with the Story-model. Other foreignkey relationships are functioning fine. Of course, the fact that the foreignkey isn’t editable means the object can’t be saved from the admin, even though MySQL shows that there is a valid story_id in the question table.

I remember having used this and that this worked fine. I suspect unicode-problems somewhere, but I can’t imagine what exactly, let alone how to fix them. Can anybody help?

PS. What happens at ForeignKey field will not appear in Django admin site isn’t the case here, I think.

  • 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-14T12:54:44+00:00Added an answer on June 14, 2026 at 12:54 pm

    Urgh.. looking for other foreignfield problems, I encountered ForeignKey field problem in Django. In the comments to the question, it is stated by Daniel Roseman that the unicode defs on models should return unicode. Tried that, and my problem was solved.

    Grrr.. Unicode… You win this time!

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

Sidebar

Related Questions

I have a table that has worked correctly for many years, but recently the
Something that has been troubling me for a while: The current wisdom is that
Something that has piqued my interest is Objective-C's BOOL type definition. Why is it
Here's something that has been bugging me... I am currently creating an application for
I am trying to do something that has been done many times before by
Not a massive problem but something that has been bugging the life out of
I am trying to update the database to show that something has been uploaded.
i have a stored procedure that has to retrieve data from multiple tables something
I want to prompt the user that something special has happened, so I want
I have a test file that has many lines, each line looks something like:

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.