Hello everyone,
I have done some tests and, in the end, I have obtained the best result by 
replicating the code of BlogPostAdmin, adapting it to my Ingredient model

ingredient_fieldsets = deepcopy(DisplayableAdmin.fieldsets)

ingredient_fieldsets[0][1]["fields"].insert(1, "name")
ingredient_fieldsets[0][1]["fields"].insert(1, "other_names")
ingredient_fieldsets[0][1]["fields"].insert(1, "information")
ingredient_fieldsets[0][1]["fields"].insert(1, "how_to_choose")
ingredient_fieldsets[0][1]["fields"].insert(1, "nutrients")
ingredient_fieldsets[0][1]["fields"].insert(1, "benefits")

ingredient_list_display = ["title", "status", "admin_link"]

ingredient_fieldsets = list(ingredient_fieldsets)
ingredient_list_filter = deepcopy(DisplayableAdmin.list_filter) + ("name", 
"other_names", "information", "how_to_choose", "nutrients", "benefits")

class IngredientAdmin(DisplayableAdmin, OwnableAdmin): 
    """
    Admin class for ingredients.
    """

    fieldsets = ingredient_fieldsets
    list_display = ingredient_list_display
    list_filter = ingredient_list_filter
    filter_horizontal = ("nutrients",)

    def save_form(self, request, form, change):
        """
        Super class ordering is important here - user must get saved first.
        """
        OwnableAdmin.save_form(self, request, form, change)
        return DisplayableAdmin.save_form(self, request, form, change)

admin.site.register(Ingredient, IngredientAdmin)

I have a single problem, if you can define problem, and is the order of the 
fields in the create/edit page, those aren't rendered in the order I have 
written in the code.


Il giorno giovedì 14 settembre 2017 13:12:56 UTC+2, Rainell Dilou Gómez ha 
scritto:
>
> Hello,
> I have created a custom content type and I have a problem with the listing 
> in the admin panel. If I extends PageAdmin
>
>
> admin.site.register(Ingredient, PageAdmin)
>
> the create/edit page is rendered as in the image
>
>
> <https://lh3.googleusercontent.com/-Ohd3o8QKwmg/WbpcWgjV5fI/AAAAAAAAAdc/i_yp_ntXQEcTMcfB8-5yFBsySLINt11sgCLcBGAs/s1600/Schermata%2B2017-09-14%2Balle%2B12.26.00.png>
>
> and this is great for creating and editing, but the listing in the page 
> section, as show in the following image, is a problem because the 
> Ingredients (my custom content type) will be many, will be hundreds.
>
>
> <https://lh3.googleusercontent.com/-Yap3P0bVjw0/WbpbLnHhsMI/AAAAAAAAAdQ/HGkHjriVlRIMgb1qoH7OMxusCZQdvoEeACLcBGAs/s1600/Schermata%2B2017-09-14%2Balle%2B12.24.32.png>
>
> If instead I don't extend PageAdmin
>
> admin.site.register(Ingredient)
>
> my custom content type list is rendered as in the following image, in a 
> more convenient way, considering that there will be hundreds of Ingredients
>
>
> <https://lh3.googleusercontent.com/-ehaJO4GKoHs/WbpfH1qDOFI/AAAAAAAAAdo/I2BKgYN5jyUADxoBgDpNIgJ3jM13JD0tACLcBGAs/s1600/Schermata%2B2017-09-14%2Balle%2B12.27.13.png>
> but the create/edit page will be rendered as in the next image, and it 
> isn't convenient, considering that the fields are twice as many as are 
> shown in this image.
>
>
> <https://lh3.googleusercontent.com/-eT-u4auTnCU/WbphFcKL65I/AAAAAAAAAd8/ZO51pAVa3SsThgkUJSPJs0OTGs_NZatIQCLcBGAs/s1600/Schermata%2B2017-09-14%2Balle%2B12.27.38.png>
>
> So how can I do to create/edit as when using PageAdmin and list as when 
> not using PageAdmin?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to