On Mon, Apr 7, 2014 at 3:04 PM, Emanuel <
costav...@gmail.com> wrote:
> Hi all!
>
> I'm have the following models:
>
> Class A(models.Model):
> pass
>
>
> Class Z(models.Model):
> pass
>
>
> Class B(models.Model):
> a = models.ForeignKey(a)
> z = models.ForeignKey(Z)
>
> def __unicode__(self):
> return self.z
>
>
> Class C(models.Model):
> b = models.ForeignKey(B)
>
>
> I Want in the admin add A,B and C objects.
>
> I know how to put inline objects of B in A. Everything works as expected.
> But I want to create new C's in the same page. Something like having C as an
> Inline of B, beeing B an Inline of A. It could appear all in popups...
nested inlines are not currently supported. A work around can be using
a readonly field on B inline that points to a B change view with C
inlines
class BInline(admin.TabularInline):
model = B
readonly_fields = ('c_link',)
def c_link(self, instance):
if not
instance.pk:
return ''
url = reverse('admin:app_c_change', args=(
instance.pk,))
popup = 'onclick="return showAddAnotherPopup(this);"'
return '<a href="%s" %s>%s</a>' % (url, popup, instance)
c_link.allow_tags=True
class CInline(admin.TabularInline):
model = C
class AModelAdmin(admin.ModelAdmin):
inlines = [BInline]
class BModelAdmin(admin.ModelAdmin):
inlines = [Cinline]