I'm not sure if this is a bug, limitation or error on my part, but I would 
like to get feedback on if there is a solution or work around to this 
issue...

In Django Admin, I have created a many-to-many inline based on a 'through' 
model `ReleaseCardCount`. The inline is linked to a parent class `Card` 
which is used for numerous child models. In Django Admin, I am only 
interested in configuring the child classes of `Card`, for example, 
`ActionCard`.

If I configure Django Admin for the parent `Card` model and 
`ReleaseCardCount` inline, I am able to add, remove and modify parent and 
inline objects without issue. If I configure the same set up for a child 
object of card, for example `ActionCard`, I can add inline objects if there 
are none or delete all inline objects, but I am unable to modify 
`ActionCard` or an inline object if an inline exists. If an inline object 
is present and I attempt to modify and save any data I get a "Please 
correct the error below" message, with no error present. 

I've minimised the code needed to recreate the issue to the following...

models.py: 

    from django.db import models

    class Release2(models.Model):
        release_id = models.AutoField(primary_key=True)
        release_name = models.CharField(max_length=100)
    
        def __str__(self):
            return self.release_name
    
    class Card2(models.Model):
        card_id = models.AutoField(primary_key=True) 
        card_name = models.CharField(max_length=100)
        release_card_count = models.ManyToManyField( Release2, 
through='ReleaseCardCount2',)
        
        def __str__(self):
            return self.card_name
    
    class ReleaseCardCount2(models.Model):
        rcc_id = models.AutoField(primary_key=True)
        rcc_release = models.ForeignKey(Release2, on_delete=models.CASCADE)
        rcc_card = models.ForeignKey(Card2, on_delete=models.CASCADE)
        rcc_count = models.PositiveIntegerField(default=1, null=True, 
blank=True)
    
    class ActionCard2(Card2):
        action_card_id = models.AutoField(primary_key=True)
        action_name = models.CharField(max_length=100)
    
        def __str__(self):
            return self.card_name
    
admin.py:

    from .models import (Release2, Card2, ReleaseCardCount2, ActionCard2)
    
    class ReleaseCardCount2InLine(admin.TabularInline):
        model = ReleaseCardCount2
        extra = 1
    
    class Card2Admin(admin.ModelAdmin):
        inlines = (ReleaseCardCount2InLine,)
        model = Card2
    
    class ActionCard2Admin(admin.ModelAdmin):
        inlines = (ReleaseCardCount2InLine,)
        model = ActionCard2
    
    admin.site.register(Release2)
    admin.site.register(Card2, Card2Admin)
    admin.site.register(ActionCard2, ActionCard2Admin)

Of interest, in my troubleshooting, I dropped and recreated the database in 
a dev environment. I found that one of the child models that was not 
working before, suddenly began to work. I suspect, that it worked due to 
being the first child model I configured Django Admin for with the inline. 
To recreate the issue with the above code, you may need try running it 
*FIRST* on the parent `Card` model. Once you have added, saved then 
modified and saved an inline object on `Card`, you can try it on 
`ActionCard`.

Relevant environment info:

 - Django - 2.0.6
 - Python - 3.6.4
 - PostgreSQL - 10.4

Thanks, Scott

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2704cc01-75de-4244-8548-7daeda18df82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to