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
424 stars 81 forks source link

Add display_fields and other attributes to crud_for_model and crud_for_app #114

Open A4TIF opened 4 years ago

A4TIF commented 4 years ago

Why not add the rest of the attributes of CRUDView?

I had to create my own function for that, but it will be nice to have it all get packaged in one method. No?

Then crud_for_model and crud_for_app is all we need to get started. Also, CRUDMixin is great too :)

oscarmlage commented 4 years ago

You mean concentrate all the model crud attributes (list_fields, display_fields, inlines...) calling the crud_for_model method?

Could be nice for all the attributes but inlines because you need to define a InlineAjaxCRUD. Would be nice if you (or anyone's else) could work in a PR to add this feature. I'll tag this issue as help wanted to give it a try.

Also would be helpful if you share the function you created to get it packaged in just a method (thanks in advance).

Thanks for the idea @kptac.

A4TIF commented 4 years ago

Ya that is exactly what I meant. All I did was copy crud_for_model method and added display_fields, search_fields, and list_filter and used my custom method in urls.py, as those were the main fields that I needed for now. I've been using my custom crud_for_model with CRUDMixin for quick results and its working great.

Something like this:

def crud_for_model(model, urlprefix=None, namespace=None, login_required=False, check_perms=False, add_form=None,
                   update_form=None, views=None, cruds_url=None, list_fields=None, related_fields=None,
                   display_fields=None, search_fields=None, list_filter=None, mixin=None):
    """
    Returns list of ``url`` items to CRUD a model.
    @param mixin=none -- mixin to be used as a base.
    """
    if mixin and not issubclass(mixin, CRUDMixin):
        raise ValueError(
            'Mixin needs to be a subclass of <%s>', CRUDMixin.__name__
        )

    mymodel = model
    myurlprefix = urlprefix
    mynamespace = namespace
    mycheck_perms = check_perms
    myadd_form = add_form
    myupdate_form = update_form
    mycruds_url = cruds_url
    mylist_fields = list_fields
    myrelated_fields = related_fields
    mydisplay_fields = display_fields
    mysearch_fields = search_fields
    mylist_filter_fields = list_filter
    mymixin = mixin

    class NOCLASS(CRUDView):
        model = mymodel
        urlprefix = myurlprefix
        namespace = mynamespace
        check_login = login_required
        check_perms = mycheck_perms
        update_form = myupdate_form
        add_form = myadd_form
        views_available = views
        cruds_url = mycruds_url
        list_fields = mylist_fields
        related_fields = myrelated_fields
        display_fields = mydisplay_fields
        search_fields = mysearch_fields
        list_filter = mylist_filter_fields
        mixin = mymixin

    nc = NOCLASS()
    return nc.get_urls()
oscarmlage commented 4 years ago

Cool!

It seems really easy to make a PR with the changes, so we can add them in the next release.

I have a challenge for you: would you like to make the PR yourself?, I will help with the review and with the documentation update, you can't say no! 😉

A4TIF commented 4 years ago

sure :)

A4TIF commented 4 years ago

@oscarmlage - Added PR, please review.

119