I have these two models:
class CoursePrefix(models.Model):
prefix = models.CharField(max_length=6)
title = models.CharField(max_length=40, blank=True)
department = models.ForeignKey(Department)
def __str__(self):
return self.prefix
class Meta:
verbose_name_plural = 'Course Prefixes'
ordering = ('prefix',)
class Course(models.Model):
prefix = models.ForeignKey(CoursePrefix)
number = models.CharField('Course Number', max_length=10)
title = models.CharField(max_length=100)
slug = models.SlugField(blank=True, help_text="This should be
'PREFIX-NUMBER' eg:AG-315")
description = models.TextField(blank=True)
ge_code = models.CharField('GE Code', max_length=6, blank=True)
prerequisites = models.BooleanField('Pre-Requesites are Required',
default=False)
specific_to_instructor = models.BooleanField(default=False,
help_text="Set to True if the course applies to sustainability only if
taught by a specific instructor")
def __str__(self):
return "%s-%s: %s" % (self.prefix, self.number, self.title)
def full_number(self):
return "%s-%s" % (self.prefix,self.number)
class Meta:
ordering = ('slug', 'number', 'title')
In the admin model for Course, I'd like to prepopulate the slug with
the concatenation of prefix and number.
prepopulated_fields = {'slug': ('prefix', 'number')}
*almost* works perfectly, except that the prefix is shown by it's
foreign key id (eg "1"), rather than the name ("BAZ"). All I could
seem to find on the subject was this (http://groups.google.com/group/
django-users/browse_thread/thread/fe3cc46ce445eaea) old thread from
2007, which suggested adding a get_fields method; adding
def get_fields(self):
return self.prefix
to CoursePrefix didn't change the output.
BTW, can we use pre tags around code, or is pasting it directly into
the message the preferred way?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---