All inline models need to have a ForeignKey pointing back to the base
model.
In your case you need to declare a ForeignKey field from Gallery model
to Business model, what you've did instead is you've created foreign
key to parent class (Directory).

Try this:

class Directory(models.Model):
    name = models.CharField(max_length=60)
class Business(Directory):
    anyfield = models.CharField(max_length=60)
class Gallery(models.Model):
    directory = models.ForeignKey(Business),
    pic =  models.ImageField(upload_to='pics')


On Feb 6, 9:56 pm, phoebebright <phoebebright...@gmail.com> wrote:
> Here is my model:
>
> class Directory(models.Model):
>     name = models.CharField(max_length=60)
>
> class Business(Directory):
>     anyfield = models.CharField(max_length=60)
>
> class Gallery(models.Model):
>     directory = models.ForeignKey(Directory),
>     pic =  models.ImageField(upload_to='pics')
>
> This is admin.py
>
> class Galleries(admin.TabularInline):
>     model = Gallery
>
> class DirectoryAdmin(admin.ModelAdmin):
>
>     inlines = [
>         Galleries,
>     ]
>
> admin.site.register(Business,DirectoryAdmin)
>
> This is the error I get in admin.
>
> Request Method:         GET
> Request URL:    http://127.0.0.1:8000/admin/town/business/add/
> Exception Type:         Exception
> Exception Value:
>
> <class 'towns.town.models.Gallery'> has no ForeignKey to <class
> 'towns.town.models.Business'>
>
> If I take out the inlines bit in admin.py and just have
>
> admin.site.register(Business)
> admin.site.register(Gallery)
>
> Then it works as expected.
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to