Coder Social home page Coder Social logo

kux / django-admin-extend Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 5.0 377 KB

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

Python 100.00%

django-admin-extend's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-admin-extend's Issues

Add package to Pypi and make it installable with pip

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.

direct assignment to the reverse side of a many-to-many set is prohibited. Use Name.set() instead.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.