kux / django-admin-extend Goto Github PK
View Code? Open in Web Editor NEWDjango app that provides an easy way of extending or overriding behaviour of ModelAdmin classes that have already been registered by other apps
License: MIT License
Django app that provides an easy way of extending or overriding behaviour of ModelAdmin classes that have already been registered by other apps
License: MIT License
Just used your code to add an admin action to a 3rd party model, and it worked like a charm.
It would be nice it could be installed with pip from Pypi. As it is, I had to manually copy your extend.py into my app. Not too bad, but I usually prefer to manage all dependencies via my requirements.txt file.
Thanks for the useful work.
It's not quite an issue because I found a way to manage..
in extend.py add_bidirectional_m2m
I had this error "direct assignment to the reverse side of a many-to-many set is prohibited"
and I use the code found by https://gist.github.com/Wtower/0b181cc06f816e4feac14e7c0aa2e9d0
def save(self, commit=True):
"""
Saves this ``form``'s cleaned_data into model instance
``self.instance``.
If commit=True, then the changes to ``instance`` will be saved to the
database. If ``instance`` is a new object then it will get saved to
the database even if commit=False
Returns ``instance``.
"""
instance = super(BidirectionalM2MForm, self).save(commit=False)
force_save = self.instance.pk is None
if force_save:
instance.save()
for m2m_field, related_manager in self._get_bidirectional_m2m_fields():
# setattr(self.instance, related_manager, self.cleaned_data[m2m_field])
# direct assignment to the reverse side of a many-to-many set is prohibited. Use suppliers.set() instead.
recordset = getattr(self.instance, m2m_field)
records = recordset.all()
# remove records that have been removed in form
for record in records:
if record not in self.cleaned_data[m2m_field]:
recordset.remove(record)
# add records that have been added in form
for record in self.cleaned_data[m2m_field]:
if record not in records:
recordset.add(record)
if commit:
if not force_save:
instance.save()
self.save_m2m()
return instance
return BidirectionalM2MForm
and it works !
Thank you
(I'm a complete newbee, I don't know how to propose the change directly in the repository)
en français :
Ca n'est pas vraiment une erreur en fait, puisque j'ai trouvé la solution.
J'avais une erreur avec le code proposé et j'ai réussi à la contourner, avec le code précisé au-dessus, mais je ne sais pas comment proposer cet rectificatif directement sur le repository.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.