The FileNode model

class media_tree.models.FileNode(*args, **kwargs)

Each FileNode instance represents a node in the media object tree, that is to say a “file” or “folder”. Accordingly, their node_type attribute can either be FileNode.FOLDER, meaning that they may have child nodes, or FileNode.FILE, meaning that they are associated to media files in storage and are storing metadata about those files.

Note

Since FileNode is a child class of MPTTModel, it inherits many methods that facilitate queries and data manipulation when working with trees.

You can access the actual media associated to a FileNode model instance using the following to field attributes:

``file``
The actual media file
``preview_file``
An optional image file that will be used for previews. This is useful for visual media that PIL cannot read, such as video files.
FILE

The constant denoting a file node, used for the node_type attribute.

FOLDER

The constant denoting a folder node, used for the node_type attribute.

alt

Returns object metadata suitable for use as the HTML alt attribute. You can use this method in templates:

<img src="{{ node.file.url }}" alt="{{ node.alt }}" />
author

Author name of the file

copyright

Copyright information for the file

created

Date and time when object was created

created_by

User that created the object

date_time

Date and time information for the file (authoring or publishing date)

description

Description for the file

extension

File extension, lowercase

extra_metadata

Extra metadata

get_admin_url()

Returns the URL for viewing a FileNode in the admin.

get_ancestors(ascending=False, include_self=False)

Creates a QuerySet containing the ancestors of this model instance.

This defaults to being in descending order (root ancestor first, immediate parent last); passing True for the ascending argument will reverse the ordering (immediate parent first, root ancestor last).

If include_self is True, the QuerySet will also include this model instance.

get_caption_formatted(field_formats={'title': '<strong>%s</strong>'}, escape=True)

Returns object metadata that has been selected to be displayed to users, compiled as a string including default formatting, for example bold titles.

You can use this method in templates where you want to output image captions.

get_caption_formatted_unescaped()

Returns object metadata that has been selected to be displayed to users, compiled as a string with the original field values left unescaped, i.e. the original field values may contain tags.

get_children()

Returns a QuerySet containing the immediate children of this model instance, in tree order.

The benefit of using this method over the reverse relation provided by the ORM to the instance’s children is that a database query can be avoided in the case where the instance is a leaf node (it has no children).

If called from a template where the tree has been walked by the cache_tree_children filter, no database query is required.

get_descendant_count()

Returns the number of descendants this model instance has.

get_descendants(include_self=False)

Creates a QuerySet containing descendants of this model instance, in tree order.

If include_self is True, the QuerySet will also include this model instance.

get_leafnodes(include_self=False)

Creates a QuerySet containing leafnodes of this model instance, in tree order.

If include_self is True, the QuerySet will also include this model instance (if it is a leaf node)

get_level()

Returns the level of this node (distance from root)

get_metadata_display(field_formats={}, escape=True)

Returns object metadata that has been selected to be displayed to users, compiled as a string.

get_metadata_display_unescaped()

Returns object metadata that has been selected to be displayed to users, compiled as a string with the original field values left unescaped, i.e. the original field values may contain tags.

get_next_sibling(**filters)

Returns this model instance’s next sibling in the tree, or None if it doesn’t have a next sibling.

get_previous_sibling(**filters)

Returns this model instance’s previous sibling in the tree, or None if it doesn’t have a previous sibling.

get_qualified_file_url(field_name='file')

Returns a fully qualified URL for the file field, including protocol, domain and port. In most cases, you can just use file.url instead, which (depending on your MEDIA_URL) may or may not contain the domain. In some cases however, you always need a fully qualified URL. This includes, for instance, embedding a flash video player from a remote domain and passing it a video URL.

get_qualified_preview_url()

Similar to get_qualified_file_url(), but returns the URL for the preview_file field, which can be used to associate image previews with video files.

get_root()

Returns the root node of this model instance’s tree.

get_siblings(include_self=False)

Creates a QuerySet containing siblings of this model instance. Root nodes are considered to be siblings of other root nodes.

If include_self is True, the QuerySet will also include this model instance.

static get_top_node()

Returns a symbolic node representing the root of all nodes. This node is not actually stored in the database, but used in the admin to link to the change list.

has_metadata

Flag specifying whether the absolute minimal metadata was entered

height

For images: height in pixels

insert_at(target, position='first-child', save=False, allow_existing_pk=False)

Convenience method for calling TreeManager.insert_node with this model instance.

is_ancestor_of(other, include_self=False)

Returns True if this model is an ancestor of the given node, False otherwise. If include_self is True, also returns True if the two nodes are the same node.

is_child_node()

Returns True if this model instance is a child node, False otherwise.

is_default

Flag whether the file is the default file in its parent folder

is_leaf_node()

Returns True if this model instance is a leaf node (it has no children), False otherwise.

is_root_node()

Returns True if this model instance is a root node, False otherwise.

is_top_node()

Returns True if the model instance is the top node.

keywords

Keywords for the file

media_type

Media type, i.e. broad category of the kind of media

mimetype

The mime type of the media file

modified

Date and time when object was last modified

modified_by

User that last modified the object

move_to(target, position='first-child')

Convenience method for calling TreeManager.move_node with this model instance.

NOTE: This is a low-level method; it does NOT respect MPTTMeta.order_insertion_by. In most cases you should just move the node yourself by setting node.parent.

name

Name of the file or folder

node_type

Type of the node (FileNode.FILE or FileNode.FOLDER)

override_alt

Alt text override. If empty, the alt text will be compiled from the all metadata that is available and flagged to be displayed.

override_caption

Caption override. If empty, the caption will be compiled from the all metadata that is available and flagged to be displayed.

parent

The parent (folder) object of the node.

position

Position of the file among its siblings, for manual ordering

publish_author

Flag to toggle whether the author name should be displayed

Flag to toggle whether copyright information should be displayed

publish_date_time

Flag to toggle whether date and time information should be displayed

published

Publish date and time

size

File size in bytes

slug

Slug for the object

title

Title for the file

width

For images: width in pixels

Previous topic

Admin interface overview

Next topic

Fields and forms

This Page