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)