Lookaway App Profile Models

Written by Kyle Bruder, published on April 5, 2021, 1:41 a.m., last updated on April 6, 2021, 8:06 p.m.


logo


The following example demonstrate how to inherit the Lookaway App Profile mixins and build on them to suit your needs. AppProfile contains basic settings such as the display name of the app. Section allows page sections to be added to the landing page.


  1. Import the App Profile Model Mixins

    Add the following line near the top of your app's 'models.py' file.

    foo/models.py
    ...
    from lookaway.mixins import AppProfile, Section
    ...

    Source: kbruder Tech


  2. Add an App Profile Model to Your App

    Here we have inherited the AppProfile model mixin and added some additional settings that can be updated to change how items appear on the landing page and list views. Add the model in your app's models.py file.

    foo/models.py
    class FooAppProfile(AppProfile):
    
        n_foo_models = models.PositiveIntegerField(default=25)
        n_bar_models = models.PositiveIntegerField(default=5)
        foo_list_pagination = models.PositiveIntegerField(default=25)
        bar_list_pagination = models.PositiveIntegerField(default=6)
        show_new_foos = models.BooleanField(default=True)
        show_top_bars = models.BooleanField(default=True)
        show_new_foos = models.BooleanField(default=True)
        show_top_bars = models.BooleanField(default=True)
        logo = models.ForeignKey(
            'objects.image',
            on_delete=models.SET_NULL,
            blank=True,
            null=True,
            related_name='foo_logo'
        )
        banner = models.ForeignKey(
            'objects.image',
            on_delete=models.SET_NULL,
            blank=True,
            null=True,
            related_name='foo_banner'
        )
        bg_image = models.ForeignKey(
            'objects.image',
            on_delete=models.SET_NULL,
            blank=True,
            null=True,
            related_name='foo_bg_image'
        )
    
        class Meta:
            verbose_name = "App Profile"
    
        def __str__(self):
            return self.title

    Source: kbruder Tech


  3. Add a Page Section Model

    Here we have inherited the Section mixin and added some fields in case we want to add alerts to the landing page. Add the model in your app's models.py file.

    foo/models.py
    class FooPageSection(Section):
    
        info = models.TextField(
            max_length=65535,
            blank=True,
            null=True,
        )
        alert = models.TextField(
            max_length=65535,
            blank=True,
            null=True,
        )
        foos = models.ManyToManyField(
            'foo.foo',
            blank=True,
        )
        bars = models.ManyToManyField(
            'foo.bar',
            blank=True,
        )
        is_enabled = models.BooleanField(default=False)
        members_only = models.BooleanField(default=False)
    
        class Meta:
            verbose_name = "Landing Page Section"
            verbose_name_plural = "Landing Page Sections"
            ordering = ['order']
    
        def __str__(self):
            return self.title

    Source: kbruder Tech


  4. Add the New Models to the Admin

    If you want to be able to access the new models in the Django Admin app, remember to register them first. Even if you plan on adding forms for these models (which is highly recommended) it is convenient to be able to use the Admin when troubleshooting code.

    foo/admin.py
    from django.contrib import admin
    from .models import FooAppProfile, FooPageSection
    ...
    admin.site.register(FooAppProfile)
    admin.site.register(FooPageSection)
    ...


  5. Migrate the Database

    Whenever an apps models have been changed or new models have been added, you must migrate the database.

    $ python manage.py makemigrations foo
    $ python manage.py migrate foo



Referenced by

App Profile Design Patterns - Lookaway CMS

Lookaway CMS comes with class mixins that can be used when writing new apps. These powerful customization features can extend your models and views.

bitcoin:3MnhNRKgrpTFQWstYicjF6GebY7u7dap4u
Bitcoin Accepted Here

3MnhNRKgrpTFQWstYicjF6GebY7u7dap4u

Please donate some Bitcoin to our site. We can use it to keep improving the site and open up to more members. Any amount will help. Thank you.


litecoin:MT61gm6pdp9rJoLyMWW5A1hnUpxAERnxqg
Litecoin Accepted Here

MT61gm6pdp9rJoLyMWW5A1hnUpxAERnxqg

Please donate some Lite to our site. We can use it to keep improving the site and open it up to more members. Any amount will help. Thank you.


Lookaway: Development Lookaway: CMS

Contributed by Kyle Bruder on April 5, 2021, 1:41 a.m.
Last updated on April 6, 2021, 8:06 p.m.