python - How to produce a TabularInline that spans models -
i have model (booking) onetoonefield (thread) subsequently has foreignkey relationship (message). show list of messages on booking admin, thread model in between appears hard/not possible?
class booking(model): ... thread = models.onetoonefield('user_messages.thread', verbose_name='thread') class thread(model): ... class message(model): thread = models.foreignkey(thread, related_name="messages")
is there way can set bookingadmin inline can display messages (spanning across thread relationship)? like:
class messageinline(tabularinline): model = message fk_name = '???' class bookingadmin(modeladmin): inlines = [messageinline, ]
i'm happy override way inlines work if that's best way, i'm not sure tackle that. looks overriding *get_formset* might trick?
this isn't tested yet, appears work. solution have inline , formset hooks replace booking attached thread...
class bookingmessageformset(baseinlineformset): '''given booking instance, divert thread''' def __init__(self, *args, **kwargs): if 'instance' in kwargs: kwargs['instance'] = kwargs['instance'].thread else: raise exception() # todo not sure if/when happens baseinlineformset.__init__(self, *args, **kwargs) class messageinline(admin.tabularinline): model = message formset = bookingmessageformset def __init__(self, parent_model, admin_site): '''override parent_model''' super(messageinline, self).__init__(thread, admin_site)
Comments
Post a Comment