Skip to content

BaseAccount model

deby edited this page Nov 19, 2021 · 7 revisions

↑ Parent: MagiModel utils

← Previous: DateTime fields

You have to provide the model class that corresponds to an account (see Start a new website):

from magi.abstract_models import BaseAccount

class Account(BaseAccount):
    class Meta:
        pass

By using BaseAccount and the default AccountCollection classes, MagiCircles will provide default templates and default behavior.

All fields in BaseAccount

Base account contains the following fields:

Field name Type Description
owner ForeignKey(User) See MagiModel, section "Have an owner"
creation DateTimeField Will save the date of creation of the account
nickname CharField Useful to allow users to differentiate their multiple accounts using their own names
start_date DateField Users can manually enter when they started playing
level PositiveIntegerField Most games have a level per account, so MagiCircles provides it by default. Can be ignores if needed.
default_tab CharField When using the default templates for profile accounts, will use this to open the account of the user's choice first
cached_leaderboard Property(int) Calculated leaderboard position according to level of other players' accounts
leaderboard_image_url Property(string) Only use this when cached_leaderboard is 1, 2 or 3. Returns an image to display that shows a medal

Fields you may want to add in your account model

Some fields are not in BaseAccount, but if you add them in your Account model, templates and logic will know how to handle expected behavior.

Note that even though you need the exact same field name, you can give it a label of your choice to have a display name that matches your needs.

If you want to personalize the templates and behavior of the default accounts, you can override variables and methods in both Account model and AccountCollection class.

Note that you can't remove any model field in BaseAccount. If you don't want to use one, just delete it from the fields in the form so it never gets populated.

Consider using MobileGameAccount, an abstract model that extends BaseAccount and adds fields that are extremely common when the site covers a mobile game. See Abstract models.

Friend ID

ℹ️ Already available if you use MobileGameAccount, see Abstract models.

class Account(BaseAccount):
    ...
    friend_id = models.PositiveIntegerField(_('Friend ID'), null=True)

If you're willing to add a unique code allowing users to find the real account in the game.

Displayed on the account details both on leaderboard and profile.

class Account(BaseAccount):
    ...
    show_friend_id = models.BooleanField(_('Should your friend ID be visible to other players?'), default=True)

Will show/hide friend id displayed on the account details both on leaderboard, profile, and profile account tab "about". Users can change their preference when editing their account.

Center
class Account(BaseAccount):
    ...
    center = models.ForeignKey('CollectibleCard', verbose_name=_('Center'), related_name='center_of_account', null=True, on_delete=models.SET_NULL)

Must be a foreign key to a collectible model. Will be select_related when listing accounts under profile (not in leaderboard).

If you keep the default profile displayer:

  • .image is required. Will display the center instead of the avatar of the user
  • .color will be used as a class panel-, otherwise css color in preferences
  • .art will be used as an image background cover instead of side small image if present
Self-service verifications

ℹ️ Already available if you use MobileGameAccount, see Abstract models.

class Account(BaseAccount):
    ...
    _thumbnail_screenshot = models.ImageField(null=True, upload_to=uploadThumb('account_screenshot'))
    screenshot = models.ImageField(
        _('Screenshot'), help_text=_('In-game profile screenshot'),
        upload_to=uploadItem('account_screenshot'), null=True)
    level_on_screenshot_upload = models.PositiveIntegerField(null=True)
    is_hidden_from_leaderboard = models.BooleanField('Hide from leaderboard', default=False, db_index=True)

Will turn on self-verification system which will prevent users from setting their level above MAX_LEVEL_BEFORE_SCREENSHOT_REQUIRED if they don't provide a screenshot.

It will also ask them to re-upload a screenshot every MAX_LEVEL_UP_STEP_BEFORE_SCREENSHOT_REQUIRED.

hidden_from_leaderboard can be set by staff manually via reports if a user keeps changing their level without providing a valid screenshot.

Playground

ℹ️ Already available if you use MobileGameAccount, see Abstract models.

class Account(BaseAccount):
    ...
    is_playground = models.BooleanField(_('Playground'), default=False, db_index=True)

Allows users to create test accounts that will be hidden from the leaderboard. They can set their account as playground when editing their account details.

ℹ︎ See also: Abstract models

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