On Sat, Aug 30, 2008 at 2:04 PM, jeffself <[EMAIL PROTECTED]> wrote: > > My model has 3 main classes, School, Contest, Participant. > > School contains the following fields: school_name, slug, nickname. > Contest contains the following fields: date_scheduled, title, notes. > Participant contains the following fields: contest (foreign key), > school (foreign key), score > > I want my Contest admin form to contain a tabular list of 2 > participants. I've added the following line to my ContestAdmin class: > inlines = [ParticipantInline] > > But where do I put my ParticipantInline class? If I put it before the > ContestAdmin class, I get an error that Participant can't be found > because my Participant class comes after the ContestAdmin class. If I > put it after the ContestAdmin class, I get an error with the > ContestAdmin class with the inlines = [ParticpiantInline] > > Here's my complete model.py: > > class School(models.Model): > school_name = models.CharField(max_length=50) > mascot = models.CharField(max_length=50) > > def __unicode__(self): > return self.school_name > > admin.site.register(School) > > class Contest(models.Model): > date_scheduled = models.DateField() > title = models.CharField(max_length=50) > > def __unicode__(self): > return self.title > > class ContestAdmin(admin.ModelAdmin): > inlines = [ParticipantInline] > > admin.site.register(Contest, ContestAdmin) > > class Participant(models.Model): > contest = models.ForeignKey(Contest) > school = models.ForeignKey(School) > score = models.PositiveIntegerField() > > class ParticipantInline(admin.TabularInline): > model = Participant > extra = 2 >
Don't intermix model and admin definitions. The recommended way is to put model definitions in models.py and admin definitions in admin.py. Then admin.autodiscover() in urls.py will load your app's admin.py and the registrations will get done once (having them in models.py risks reigstration errors if/when your models.py gets loaded more than once). This will also solve your ordering problem. Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---