jschrewe / django-mongoadmin

Integrates mongodb into django's admin
http://www.schafproductions.com/projects/mongo-admin/
BSD 3-Clause "New" or "Revised" License
112 stars 38 forks source link

Issues with Inheritance #9

Open KMontag42 opened 12 years ago

KMontag42 commented 12 years ago

Hey,

I'm trying to setup some inherited documents in my db, and I'm having some issues with viewing the base class in mongoadmin.

Here is my code: Admin.py:

class ActivityAdmin(DocumentAdmin):
    model = BaseActivity
    list_display = ('date_created', 'creator', 'targets',)

class FanActivityAdmin(DocumentAdmin):
    #model = FanActivity
    #list_display = ('date_created', 'creator', 'targets',)
    pass

class EventActivityAdmin(DocumentAdmin):
    #model = EventActivity
    #list_display = ('date_created', 'creator', 'targets',)
    pass

class VenueActivityAdmin(DocumentAdmin):
    #model = VenueActivity
    #list_display = ('date_created', 'creator', 'targets',)
    pass

class ArtistActivityAdmin(DocumentAdmin):
    #model = ArtistActivity
    #list_display = ('date_created', 'creator', 'targets',)
    pass

site.register(FanActivity, FanActivityAdmin)
site.register(EventActivity, EventActivityAdmin)
site.register(VenueActivity, VenueActivityAdmin)
site.register(ArtistActivity, ArtistActivityAdmin)
site.register(BaseActivity, ActivityAdmin)

Models.py:

class BaseActivity(BaseDocument):
    creator          = EmbeddedDocumentField('Creator')
    targets          = ListField(EmbeddedDocumentField('Target'))

    meta = {'allow_inheritance' : True, 'queryset_class' : BaseActivityManager}

class FanActivity(BaseActivity):
    #_admin_opts = BaseActivity
    pass

class ArtistActivity(BaseActivity):
    #_admin_opts = ArtistActivityAdmin
    pass
class VenueActivity(BaseActivity):
   # _admin_opts = VenueActivityAdmin
    pass
class EventActivity(BaseActivity):
    #_admin_opts = EventActivityAdmin
    pass

This is the error I get when I try to go to /mongoadmin/activity/baseactivity: AttributeError at /mongoadmin/activity/baseactivity/ 'FanActivity' object has no attribute '_admin_opts'

Now, when I try to uncomment the _admin_opts attribute to the models, here is what I get: AttributeError at /mongoadmin/activity/baseactivity/ type object 'BaseActivity' has no attribute 'get_field_by_name'

What am I doing wrong??

Thanks for your help!

jschrewe commented 12 years ago

Hey,

You are probably doing nothing wrong and have met one of the untested and apparently unsupported cases :(

_admin_opts is monkey patched into the document by mongoadmin and provides a wrapper for mongoengine's meta dict because mongoengine's meta dict does not work with Django. As is get_field_by_namewhich doesn't exist in mongoengine documents but is required by Django.

I hope I can take a look at inheritance this weekend. Sadly I don't have time sooner. Till then you can either write the patch yourself or live with inheritance being unsupported. Sorry.

KMontag42 commented 12 years ago

No problem!

Temporarily, until I figure out a better way to deal with the issue, I've just left out the BaseActivity admin and it is working fine, I can view the other records no problem.

I may end up writing the patch myself, it depends on what else comes up this week. If I do I'll obviously post my changes.

Thanks!

jschrewe commented 12 years ago

Posting a patch would be nice!

Cheers.