Coder Social home page Coder Social logo

Add Site Setting to the demo about bakerydemo HOT 3 CLOSED

lb- avatar lb- commented on July 17, 2024 1
Add Site Setting to the demo

from bakerydemo.

Comments (3)

Imshk avatar Imshk commented on July 17, 2024

I would to like to help on this issue , please provide me more information so I can solve it .

from bakerydemo.

Hanoon02 avatar Hanoon02 commented on July 17, 2024

Hi, I have made a rough sketch of the steps needed to complete this task. Points taken from https://docs.wagtail.org/en/stable/reference/contrib/settings.html. If its valid can I do a PR and add these changes?

We create a new app within the bakerydemo project using python manage.py startapp mysettings
Add it to the INSTALLED_APPS setting -

INSTALLED_APPS = [
 ...
    'mysettings',
 ...
]

Now, create a models.py file in the mysettings app directory and import the BaseSiteSettings model from wagtail.contrib.settings.models

from wagtail.contrib.settings.models import BaseSiteSettings

class MySiteSettings(BaseSiteSettings):
    footer_text = models.CharField(
        verbose_name='Footer text',
        max_length=255,
        null=True,
        blank=True,
    )

    panels = BaseSiteSettings.panels + [
        FieldPanel('footer_text'),
    ]

    class Meta:
        verbose_name = 'Site settings'
        verbose_name_plural = 'Site settings'

Here, I've made MySiteSettings model that extends the BaseSiteSettings model and adds a footer_text field. It also have new panels attribute that includes the footer_text field in the admin interface.

Now, to use the new Site Settings, register it with Wagtail wagtail_hooks.py file

from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register
from .models import MySiteSettings

class MySiteSettingsAdmin(ModelAdmin):
    model = MySiteSettings
    menu_label = 'Site settings'

modeladmin_register(MySiteSettingsAdmin)

I have extended the ModelAdmin class and set the model attribute to the new setting

Finally run the make migration codes as usual

For site-wide settings, change this in settings.py, so the new settings model is used - WAGTAIL_SITE_SETTINGS_MODEL = 'mysettings.MySiteSettings'

For using BaseGenericSetting as logo, we create a new model that inherits from BaseGenericSetting to represent the logo, and then register it with Wagtail in your app's wagtail_hooks.py file.

from bakerydemo.

lb- avatar lb- commented on July 17, 2024

Hey @Hanoon02 thanks for this, I realised that the bakery demo site already has a footer model. It's a snippet.

Maybe the site setting could be a simple title suffix (that can be translated), one single char field.
This could then be used here https://github.com/wagtail/bakerydemo/blob/main/bakerydemo/templates/base.html#L15

A second field this model could be a colour field and then this sets the theme colour meta tag. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name/theme-color

Also, I don't think we would need a new app for this, in the base app is fine. Another thing that will need to be in the PR is the fixtures data.

from bakerydemo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.