Thursday, November 20, 2014

problem implementing admin inline

I have a <article> model that has a foreignKey to a <module> model.  I want to be able to edit the <module> model within the <article> admin

in moduleApp.models I have something like:
class module(models.Model):
  HTML = models.TextField( blank=True, null=True )

in articleApp.models I have something like:
class article(models.Model)
  HomePageModule = models.ForeignKey(module, blank=True, null=True)

In the admin I have something:
class moduleInline(admin.TabularInline):
    model = module

class ArticleAdmin(admin.ModelAdmin):
    inlines = [moduleInline,]
   
I'm getting the error XXX has no ForeignKey to XXX.

I've found a few other people with the problem and it seems like the problem is that I need to change up the moduleInline to articleInline.
http://stackoverflow.com/questions/21899523/inline-in-django-admin-has-no-foreignkey
http://stackoverflow.com/questions/8526159/django-inline-has-no-foreignkey-to

I'm trying to keep my moduleApp as a stand alone app and use it in multiple other apps.  To achieve this I'll have to move all the admin code in the module app.  This defeats my desire to make moduleApp a stand alone app. 

Is there a way I can make inlines work for this?  If not, what is the best way to get this done?  I've got a highly customized admin so I don't mind making the edits. 

Brian

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/02d1f2b1-99a0-40d0-803a-d440d370c433%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment