oscarmlage / django-cruds-adminlte

django-cruds is simple drop-in django app that creates CRUD for faster prototyping
BSD 3-Clause "New" or "Revised" License
425 stars 81 forks source link

Added support for custom mixin for <crud_for_app> and <crud_for_model> #99

Closed rtubio closed 5 years ago

rtubio commented 5 years ago

This modification permits passing a custom CRUDMixin, that permits customizing certain parts of the code like "get_context_data". This permits users to set their own context and keep it throughout all the views.

Now, it is possible to pass the new CRUDMixin class as a parameter for "crud_for_app" and for "crud_for_model"; like this:

    class Mixin(CRUDMixin):
        def get_context_data(self, *args, **kwargs):
            context = super(Mixin, self).get_context_data(*args, **kwargs)
            context['cars'] = MyModel.objects.all()
            return context

    urlpatterns += crud_for_app('myapp', login_required=True, mixin=Mixin)

This modification checks whether the new class "mixin" is a subclass of CRUDMixin or not. If not, it raises a ValueError exception.

oscarmlage commented 5 years ago

Thanks for the work @rtubio. It would be nice if you may write some comment (like the above one explaining how to use the mixin) in the doc/installation.rst or doc/usage.rst or even extend the demo/testapp app to show it.

Thanks again for the improvement.

rtubio commented 5 years ago

Yes, I will try to add today the example to the documentation; it looks to me that it will fit in the "usage" section. I am currently using this library for a personal project, so I will try to keep helping you guys in improving it.

oscarmlage commented 5 years ago

Thanks @rtubio. If you don't mind I would like to add you to the project's contributors list

oscarmlage commented 5 years ago

It seems that there is a problem passing the mixin as argument in crud_for_model method (issue #102, python3 + django2), please have a look yourself when you have time. I'll revert the PR to avoid more issues like #102 while it's not solved.

Seykotron commented 5 years ago

Im having the same issue as #102 how can I fix it?

I installed it with pip install, didnt pull the code from the repository itself.

Thank you!

oscarmlage commented 5 years ago

@Seykotron PR was merged but there is no new release since that, there is a plan to publish next release in a few, so you could install it freshly from pip too :-)

Seykotron commented 5 years ago

@oscarmlage Great, I thought on a feature to personalize the URL not just taking the name of the app/model/[list|update|etc..] I have it working on my own project, maybe I could do a merge request with it?

Thank you for the fast reply @oscarmlage,

Un placer ;)

oscarmlage commented 5 years ago

maybe I could do a merge request with it?

Sure dude!, thanks a lot.

El placer es mío ;-)