On Dec 22, 7:04 pm, Malcolm Tredinnick <malc...@pointy-stick.com> wrote:
> On Mon, 2008-12-22 at 09:42 -0800, George Sakkis wrote: > > [...] > > > > > Unfortunately it doesn't work for what I tried. What I am trying to do > > is have the Child classes as InlineModelAdmin in some other class that > > references them. Here's a sample: > > > # ======= models.py =================== > > class Review(models.Model): > > # general fields > > class Meta: > > abstract = True > > > class BookReview(Review): > > # book-specific review fields > > > class MoviewReview(Review): > > # movie-specific review fields > > > # ======= admin.py =================== > > > class ReviewInline(admin.StackedInline): > > model = models.Review > > extra = 0 > > > class UserReviewAdmin(admin.ModelAdmin): > > inlines = [ReviewInline] > > # more stuff > > > admin.site.register(models.User, UserReviewAdmin) > > > This dies with "type object 'Review' has no attribute > > '_default_manager'", apparently because Review is not a table-backed > > model. What should I be doing differently ? > > I don't really understand at all why you're trying to create the admin > like this. You want to edit BookReview and MovieReview objects, so > create admin classes for those two models. Creating an admin class for > Review is impossible (since it's abstract -- which wasn't something I > realised you were doing in your original explanation) and not really > necessary, since it's not Review objects that you're editing. Thanks, that's what I eventually did, and it sort of works. There are at least two reasons though I'd like to be able to declare generic Reviews: 1. With explicit concrete inline admin classes, the interface shows one section per class ("Book reviews", "Movie reviews", etc.). This might be a feature under some circumstances (you get a "group by review type" for free), but an inconvenience if you want to show a single list of all reviews regardless of type (a more real use case is entities that have children of a single review class only, e.g. only movie reviews; these will still show up sections for all review types, although it is guaranteed that only one section will be non-empty). 2. The main problem though is that it essentially cancels the major benefit of inheritance: polymorphism. Every time I add a new Review model subclass, I have to add a respective ModelAdmin subclass *and* add it explicitly to the inlines of every ModelAdmin that handles lists of reviews, i.e. change at least three places instead of one. Apparently inheritance doesn't buy me much this way; might as well code each review type completely independently. It would be neat if by declaring inlines = [ReviewInline], there was a single "Reviews" section listing all child reviews, regardless of type. A future feature request maybe ? George --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---