Skip to content

Customize views with MagiModel properties

deby edited this page Feb 14, 2023 · 8 revisions

↑ Parent: MagiModel utils

← Previous: Use an internal cache for foreign keys in models

Within your model, you may set the following properties in order to customize the views without having to change the HTML yourself:

Key Description Example Set per view
display_name When show_items_names is set to True in list view, the displayed name can be set using this property property(lambda _s: u'{} - 3'.format(_s.t_name)) display_name_in_list
display_name_item
top_image The image URL to display on top of the details of an item view or in list view property(lambda _s: _s.image_url or staticImageURL('defaults/song.png')) top_image_list
top_image_item
top_image_hd HD version of the top_image, loads in Javascript based on screen size + is used as a link to open full image in new tab property(lambda _s: _s.art_2x_url if _s.art_2x else _s.art_original_url). Already defaults to image_2x_url if it's in the model (see "2x images" in MagiModel images and files) top_image_item_hd
top_html By default, on top of the details of an item view or in list view, the items images will be displayed, or their name otherwise. This allows you to replace this with your own HTML property(lambda _s: markSafeFormat(u'<b>{}%</b><br><i>{}</i>', _s.stat, _s.t_name)) top_html_list
top_html_item
html_attributes Dict of HTML attributes to add to the HTML element of an item in a list { 'width': '500px' } html_attributes_in_list
html_attributes_item
share_image When someone shares the page on social media, an image preview shows up. It can be changed with this. property(lambda _s: _s.idolized_image or _s.normal_image) share_image_in_list
display_item_url URL to link to item (mostly used in list view). It will only replace it in this context of displaying it. To change the URL everywhere, use get_item_url (see MagiModel utils) property(lambda _s: u'/other_url?id={}'.format(_s.id))
display_ajax _item_url Same as display_item_url but for Ajax URL (opened in modal for example)
{field_name} _HIDE_WHEN _DEFAULT Don't show this field when its value is the default value. Example: is_special_song boolean, with default = False, when using this setting, will only display that it's a special song when it's a special song! True

example

When using reverse relations and many to many fields (see "Reverse relations and many to many" in MagiFields), some settings are also available for customization.

For example, an Idol Item view displays the list of cards associated with that idol. The customization options here would be in the Card model.

Key Description Example
icon_for_prefetched Icon to display on the left of the field event
image_for_prefetched Image to display on the right or within the gallery. Can be set to -1 to not show any image (defaults to text) event.png
template_for_prefetched Path to template to use to display the items. When it's displayed as a gallery, the following template variables are available: parent_item and items

→ Next: Events

I. Introduction

II. Tutorials

  1. Collections
    1. MagiModel
    2. MagiCollection
    3. MagiForm
    4. MagiFiltersForm
    5. MagiFields
  2. Single pages
  3. Configuring the navbar

III. References

IV. Utils

V. Advanced tutorials

VI. More

Clone this wiki locally