Re: [mezzanine-users] Re: How can I do to create/edit as when using PageAdmin and list as when not using PageAdmin?

2017-09-18 Thread Roger van Schie
Hi Rainell

I've done the following in the past, which allows me to dictate the order
they appear in.

form_fieldsets = deepcopy(PageAdmin.fieldsets)
form_fieldsets[0][1]["fields"][12:0] = ["hero_image", "hero_heading",
"hero_text", "content_heading", "content", "button_text",
"contact_email_sa", "contact_tel_sa", "contact_email_kenya",
"contact_tel_kenya", "response" ]
form_fieldsets = list(form_fieldsets)

Regards
Roger

On 18 September 2017 at 13:39, Rainell Dilou Gómez 
wrote:

> 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
>>
>>
>> 
>>
>> 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.
>>
>>
>> 
>>
>> 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
>>
>>
>> 
>> 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.
>>
>>
>> 
>>
>> 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 mezzanine-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Re: How can I do to create/edit as when using PageAdmin and list as when not using PageAdmin?

2017-09-15 Thread Joseph Mohan
Awesome!

That's a great talk Edwardo and a brilliant resource Roger.

I've been using Mezzanine for 2/3 years and only been coding for a few
years longer than that, so getting my head round Mezzanine has been an
excellent learning curve with code (and git).

Why don't you guys have this info/links up in the docs? I've only seen a
few Mezzanine youtubes and examples are pretty thin. Or is there a good
mezzanine resource list somewhere that i've missed?

I'm still a bit scared to contribute code-wise but if you want me to start
putting together a resources list i'd love to help






On Fri, Sep 15, 2017 at 9:19 AM, Rainell Dilou Gómez <
rainell.di...@gmail.com> wrote:

> Hi, Roger.
> I am very grateful for your kindness, also for understanding what it feels
> like to be a beginner. The example project you have published will be very
> useful for me, I greatly appreciate it.
>
> I have seen how the many to many relationship is established in the
> admin.py file of the Blog application, they use filter_horizontal
>
> filter_horizontal = ("categories", "related_recipes")
>
> then it would be sufficient to add ingredients in the recipe class
>
> filter_horizontal = ("categories", "ingredients", "related_recipes",)
>
> Again, thank you very much for everything.
>
>
> 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
>>
>>
>> 
>>
>> 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.
>>
>>
>> 
>>
>> 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
>>
>>
>> 
>> 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.
>>
>>
>> 
>>
>> 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 mezzanine-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Re: How can I do to create/edit as when using PageAdmin and list as when not using PageAdmin?

2017-09-14 Thread Eduardo Rivas
What have you tried? Django should create the migration when you swap 
out the subclasses. It's mostly going to remove fields since Page is a 
subclass of Displayable anyways.


There's also the nuclear option of just migrating your app back to zero 
to delete the tables and just create a new migration history with the 
correct parent class. Most of the time I don't mind doing this in 
development because it's just dummy data anyways. However, if losing 
data is not an option, you can dump the Page-based data to a fixture, 
manually remove the fields you don't need, and reuse the fixture to 
restore the Displayable-based model.



On 2017-09-14 4:14 PM, Andrey inte wrote:

Is there a way to migrate from Page to Displayable?
I have tried and it seems to be a pain...



--
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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Re: How can I do to create/edit as when using PageAdmin and list as when not using PageAdmin?

2017-09-14 Thread Eduardo Rivas

When I develop a Mezzanine site, there's usually two types of models I use:

1. Custom Page types. These are models that users want to incorporate 
into the page menu, and they must be editable/orderable from the page 
tree in the admin. In this case the model must inherit from 
mezzanine.pages.models.Page and the admin class must inherit from 
mezzanine.pages.admin.PageAdmin.


2. Displayable models. These are models we don't want to incorporate 
into the page menu, we want them to have their own section in the public 
site and their own list-enabled admin interface. The prime example is 
Mezzanine's built-in blog. It has it's own admin and it's own urls to 
display the BlogPost list and detail views. In this case the model must 
inherit from mezzanine.core.models.Displayable and the admin class from 
mezzanine.core.admin.DisplayableAdmin.


It looks to me like you want to go with approach #2. I suggest you 
re-write your models to use the Displayable base model and admin.


I gave a talk last year regarding this topic at DjangoCon. It explains 
how to convert a normal Django app into a Displayable-based Mezzanine 
app. Hopefully it'll be useful: https://www.youtube.com/watch?v=yVAmMXES2EU



On 2017-09-14 9:36 AM, Joseph Mohan wrote:
Yes, i've ran into this sort of thing a few times and not been able to 
figure an easy way so I try to use non-Page models..


A solution that I have used is to create a custom admin page and show 
a list of your custom pages. Not an elegant solution at all.


I'm really interested to see if ayone else ever deals with this!

On Thu, Sep 14, 2017 at 2:10 PM, Rainell Dilou Gómez 
> wrote:


Yes, I've illustrated above, if I do it like in Django Polls
Tutorial, just admin.site.register (Ingredient)

the listing will be ok, but in this case, the rendering of
creating/editing page isn't convenient, considering the number of
fields that need to be filled. For the creating/editing page would
be much more convenient to obtain a result equal to that obtained
using PageAdmin.

The most convenient result would be a simple listing (see third
image), which we can obtain following the example of Django Polls
Tutorial ( just admin.site.register(Ingredient) ) and an
creat/edit page as the one we can obtain using PageAdmin (
dmin.site.register(Ingredient, PageAdmin). See first image ). But
how to do it?


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





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.





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




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.





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 mezzanine-users+unsubscr...@googlegroups.com
.
For more options, visit https://groups.google.com/d/optout
.


--
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