-
Notifications
You must be signed in to change notification settings - Fork 11
Abstract models
↑ Parent: References
← Previous: MagiCollection settings
Abstract models are models that don't exist in the database, but you can use as a base for your own models using inheritance.
MagiCircles provides some abstract models for you:
-
A
BaseAccount
class, which can be used in inheritance when creating yourAccount
model (required). -
AccountAsOwnerModel
, useful for models that are linked to anAccount
instead of aUser
-
CacheOwner
, for any other model that doesn't have aUser
as an owner. |MobileGameAccount
, an extension of BaseAccount that provides fields that are very common in the context of mobile games - A bunch of tools around events, a common model
It's highly recommended to use this class to create the required account_model
for your project (see ACCOUNT_MODEL
in the required Website settings).
# models.py
from magi.abstract_models import BaseAccount
class Account(BaseAccount):
...
ℹ︎ See also: BaseAccount model
If your model doesn't have an owner
field but has an account
field which you're using to retrieve the owner, you can use AccountAsOwnerModel
. It will cache the required owner id for you, avoiding any extra query or join when MagiCircles will use check for permissions.
# models.py
from magi.abstract_models import AccountAsOwnerModel
class CollectibleCard(AccountAsOwnerModel):
...
ℹ︎ See also: MagiModel, section "Have an owner"
Most of the time, you will not need to display any information related to the owner of an item.
If you do, it's recommended to use an internal cache. In that case, you don't need to write the code for the cache yourself, you can just inherit from CacheOwner
:
${PROJECT}/models.py
from magi.abstract_models import CacheOwner
class Card(CacheOwner):
...
You will then be able to use the details of the owner without extra query or join by doing so:
card = models.Card.objects.get(id=1)
print card.cached_owner.username
No extra field is added besides caching fields.
cached_owner
is a property attr dict that contains the following:
- pk, id
- username
- item_url, ajax_item_url, full_item_url, http_item_url, share_url
- preferences
- i_status, status, t_status
- color, localized_color, hex_color, rgb_color, css_color
${PROJECT}/models.py
:
from magi.abstract_models import MobileGameAccount
class Account(MobileGameAccount):
...
In addition to all the fields in BaseAccount model, the following fields are also available:
Field name | Type | Description | Default |
---|---|---|---|
friend_id |
CharField(100) | Most games provide a friend ID or friend code you can share with other players to follow them in-game. Only accepts Numbers | None |
show_friend_id |
BooleanField | Show or hide that code to other players? | True |
accept_friend_requests |
NullBooleanField | Indicates to other players wether you'll accept their friend request or not | True |
i_play_with |
Save choices values as integer rather than strings | Choices are: Thumbs, Fingers, Index, Hand, Other | None |
i_os |
Save choices values as integer rather than strings | Operating System. Choices are: iOs, Android | None |
device |
CharField(150) | The model of your device. Example: Nexus 5, iPhone 4, iPad 2, ... | |
screenshot |
ImageField | See "Self-service verifications" in BaseAccount model | None |
_thumbnail_screenshot |
ImageField | See "Self-service verifications" in BaseAccount model and MagiModel images and files | None |
level_on_screenshot_upload |
PositiveIntegerField | See "Self-service verifications" in BaseAccount model | None |
is_hidden_from_leaderboard |
BooleanField | See "Self-service verifications" in BaseAccount model | False |
is_playground |
BooleanField | See "Self-service verifications" in BaseAccount model | False |
${PROJECT}/models.py
:
from magi.abstract_models import BaseEvent
class Event(BaseEvent):
...
If your events have "versions", you can also use getBaseEventWithVersions
.
ℹ︎ See also: Events
${PROJECT}/models.py
:
from magi.abstract_models import BaseEventParticipation
class EventParticipation(BaseEventParticipation):
...
ℹ︎ See also: Events
→ Next: Abstract collections
I. Introduction
II. Tutorials
III. References
- Files tree
- Default collections
- Default pages
- Website settings
- MagiCollection settings
- Abstract models
- Abstract collections
- MagiForm settings
- MagiFiltersForm settings
- Single pages settings
IV. Utils
-
MagiModel utils
- MagiModel images and files
- DateTime fields
- BaseAccount model
- Save choices values as integer rather than strings
- Store comma separated values
- Store dictionaries
- Store Markdown texts
- Translate fields values in multiple languages
- Store JSON
- More model field types
- Transform images before saving them
- Check choices at form level instead of model level
- Use an internal cache for foreign keys in models
- Customize views with MagiModel properties
- Events
- Form utils
- Python utils
- Templates utils
- Javascript utils
- Enable and disable existing collections and pages
- Translations
- Page titles and descriptions
- Characters
- Seasons
- Roles and permissions
- Allow your staff team to change configurations
- Custom users preferences and settings
- Background illustrations
- Activities tabs
- Corner popups
VI. More