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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:14:15+00:00 2026-05-13T16:14:15+00:00

I am using a ForeignKey called Memberno in My Django models. After entering data

  • 0

I am using a ForeignKey called Memberno in My Django models. After entering data in the Members Class, it appears in the other classes as “member object” in the ‘memberno’ field. For ForeignKey, I am using ‘raw_id_fields’ as a workaround, but for normal fields and even ‘filter_horizontal’ , each memberno value is displayed as “member object”. I would like the values to appear as they are in the member class i.e. 1, 2, …

from django.db import models

# Create your models here.
class Members(models.Model):
    DESIGNATION_CHOICES=(
    ('ADM', 'Administrator'),
    ('OFF', 'Club Official'),
    ('MEM', 'Ordinary Member'),
    )
    memberno = models.AutoField(primary_key=True)
    fname = models.CharField(max_length=15)
    sname = models.CharField(max_length=15)
    onames = models.CharField(max_length=30, blank=True)
    email = models.EmailField()
    phoneNumber = models.CharField(max_length=15)
    regNo = models.CharField(max_length=15)
    designation = models.CharField(max_length=3,choices=DESIGNATION_CHOICES)
    image = models.ImageField(max_length=100,upload_to='photos/%Y/%m/%d', blank=True, null=True)
    course = models.CharField(max_length=30, blank=True, null=True)


def __unicode__(self):
    return  u'%s %s %s' % (self.fname, self.sname, self.memberno)


def get_absolute_url(self):
    return '%s%s/%s' % (settings.MEDIA_URL, settings.ATTACHMENT_FOLDER, self.id)

def get_download_url(self):
    return '%s%s/%s' % (settings.MEDIA_URL, settings.ATTACHMENT_FOLDER, self.name)




class Security(models.Model):
    memberno = models.ForeignKey(Members, unique=True)
    username = models.CharField(max_length=30, primary_key=True)
    password = models.CharField(max_length=70)

def __unicode__(self):
    return  u'%s %s %s' % (self.username, self.password, self.memberno)


class Subscriptions(models.Model):
    memberno = models.ForeignKey(Members)
    receiptNo = models.CharField(max_length=30, primary_key=True)
    type = models.CharField(max_length=50)
    date = models.DateField()
    amount = models.FloatField(max_length=99)

def __unicode__(self):
    return  u'%s %s %s' % (self.receiptno, self.type, self.memberno)




class events(models.Model):
    eventName  = models.CharField(max_length=25)
    eventID =  models.AutoField(primary_key=True)
    details = models.TextField()
    attendanceFee = models.FloatField(max_length=99)
    date = models.DateField()
    memberno = models.ManyToManyField(Members)



def __unicode__(self):
    return  u'%s %s %s' % (self.eventName, self.eventID, self.memberno)
  • 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-05-13T16:14:15+00:00Added an answer on May 13, 2026 at 4:14 pm

    The admin interface appears to use __str__() to determine the display of a model. I make it a habbit to always define both __unicode__() and __str__() when I create a model. For example:

    class Activity(models.Model):
        activity_code = models.ForeignKey(ActivityCode)
        note = models.TextField(blank=True)
        def __str__(self):
            return "(%s) %s" % (self.activity_code.short, self.note)
        def __unicode__(self):
            return u'(%s) %s' % (self.activity_code.short, self.note)
    

    Update:
    It looks as though your def __unicode__(self) is not indented properly in your code. As a result it is not a part of your class, and is not being used. Indenting is very important in Python.

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

Sidebar

Related Questions

I have a table called Picture in my database. I'm using the primary key
Newbie question. Pylons 1 + SQLA using declarative style. New to Python. I have
I am using authlogic to do my authentication. The current model that serves as
I'm using self-tracking entities in a WCF client-server application. My WCF service returns various
I started using NHibernate today, but I cannot figure out how I setup a
I have a table called users and each user can belong to one group,
I am designing a web application using Mysql as the back end - and
I have a table (in MySQL) called unused with about 5.4 million rows. The
I got a question about inserting an entity with dependent entities using RIA Services
I have two tables linked by a foreign key. Example: CREATE TABLE one (id

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.