Thursday, February 28, 2019

How to override the ModelAdmin "change" form ?

Hi,

I'm currently struggling with a custom ModelAdmin.

Considering the following model:


# Bloc fonctionnel
class Assembly(Item):

    product = models.ForeignKey(to='ProductFamily', on_delete=models.CASCADE, null=True, verbose_name=_('Famille Produit'))
    functions
= models.ManyToManyField(Function, verbose_name=_('Fonctions'))
   
performances = models.ManyToManyField(Performance, verbose_name=_('Performances'), related_name='performances')

   
def _get_type(self):
       
return ItemType.ASSEMBLY

   
class Meta:
        verbose_name
= _('Bloc Fonctionnel')
        verbose_name_plural
= _('Blocs Fonctionnels')



I have a custom AssemblyAdmin related to it and also a custom AssemblyForm for customizing some fieds.

The performances m2m field is critical.  
The performances are captured in the form with a dynamic_raw_id field, which works fine.

But when this field is modified, some updates/deletions might be applied in other tables of the database.
For this purpose, I need to collect the "performance" pk captured in the html form and compare them with those currently in the database.

Basically, when the user clicks on the regular "Save" or "Save and continue" button, I would need to display an alert form (like when you click on the delete button) to explain what would happen.

I struggled with some ajax routines but it does not work as expected. 

I don't know if it's really doable and how to achieve it.

Any suggestion is welcome.

Cheers.

Z.







--
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+unsubscribe@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/88135218-a965-46c8-a454-c0376a5682f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment