Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add display_fields and other attributes to crud_for_model and crud_for_app #114

Open
A4TIF opened this issue Aug 5, 2019 · 5 comments
Open

Comments

@A4TIF
Copy link
Contributor

A4TIF commented Aug 5, 2019

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
Copy link
Owner

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.

@oscarmlage oscarmlage added this to the next release milestone Aug 20, 2019
@A4TIF
Copy link
Contributor Author

A4TIF commented Aug 20, 2019

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
Copy link
Owner

oscarmlage commented Aug 20, 2019

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
Copy link
Contributor Author

A4TIF commented Aug 20, 2019

sure :)

@A4TIF
Copy link
Contributor Author

A4TIF commented Aug 21, 2019

@oscarmlage - Added PR, please review.

#119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants