ModelWithFlag Model

siteflags.models.ModelWithFlag is practically all that’s needed for flagging.

Methods

get_flags_for_type([mdl_classes=None, [user=None[, status=None[, allow_empty=False]]]]):

Returns a dictionary with flag objects associated with the given model classes (types). The dictionary is indexed by model classes. Each dict entry contains a list of associated flag objects.

Parameters:
  • mdl_classes (list) – Classes objects (types) list to get flags for.
  • user (User) – Optional user filter
  • status (int) – Optional status filter
  • allow_empty (bool) – Include results for all given types, even those without associated flags.
get_flags_for_objects(objects_list, [user=None[, status=None]]):

Returns a dictionary with flag objects associated with the given objects. The dictionary is indexed by objects IDs. Each dict entry contains a list of associated flag objects.

Parameters:
  • QuerySet objects_list (list,) – Homogeneous objects list to get flags for.
  • user (User) – Optional user filter
  • status (int) – Optional status filter
get_flags([user=None[, status=None]]):

Returns flags for the object optionally filtered by user and/or status.

Parameters:
  • user (User) – Optional user filter
  • status (int) – Optional status filter
set_flag(user[, note=None[, status=None]]):

Flags the object.

Parameters:
  • user (User) –
  • note (str) – User-defined note for this flag.
  • status (int) – Optional status integer (the meaning is defined by a developer).
remove_flag([user=None[, status=None]]):

Removes flag(s) from the object.

Parameters:
  • user (User) – Optional user filter
  • status (int) – Optional status filter
is_flagged([user=None[, status=None]]):

Returns boolean whether the objects is flagged by a user.

Parameters:
  • user (User) –
  • status (int) – Optional status filter

Customization

SiteFlags allows you to customize Flags model.

  1. Define your own flag model inherited from FlagBase.

2. Now when models.py in your application has the definition of a custom flags model, you need to instruct Django to use it for your project instead of a built-in one:

# Somewhere in your settings.py do the following.
# Here `myapp` is the name of your application, `MyFlag` is the names of your customized model.
SITEFLAGS_FLAG_MODEL = 'myapp.MyFlag'
  1. Run manage.py makemigrations and manage.py migrate to install your customized models into DB.