I am trying to learn how to use Django.
I created 2 very simple models:
models.py
class Course(models.Model):
name = models.CharField(max_length=100)
instructor = models.CharField(max_length=100)
student = models.ForeignKey('Student', null=True, blank=True)
def __str__(self):
return (self.name)
class Student(models.Model):
name = models.CharField(max_length=100)
courses = RelatedObjectsDescriptor()
class CourseInline(admin.TabularInline):
model = Course
form = CourseForm
extra = 3
class StudentAdmin(admin.ModelAdmin):
form = StudentForm
search_fields = ('name', )
fields = ('name', )
ordering = ('name',)
inlines = [CourseInline]
admin.site.register(Student, StudentAdmin)
with this setup, I can add student then add courses to the student.
What I am trying to do is to use script to enter the known records:
student = Student(name ='student1') - This work
course = Course(name='Math101", instructor="Smith", student=student) - This work, but when I view the student record via admin page, the course does not show up as an inline object
Apr 5 |