
    $g6                     x    d dl mZ d dlmZ d dlmZmZ ddlmZm	Z	m
Z
 e
j         G d de                      ZdS )	    )models	force_str)conditional_escape	mark_safe   )ColumnLinkTransformlibraryc                   N     e Zd ZdZ	 d	 fd	Zd Zd Zd Zed             Z	 xZ
S )
ManyToManyColumna  
    Display the list of objects from a `ManyRelatedManager`

    Ordering is disabled for this column.

    Arguments:
        transform: callable to transform each item to text, it gets an item as argument
            and must return a string-like representation of the item.
            By default, it calls `~django.utils.force_str` on each item.
        filter: callable to filter, limit or order the QuerySet, it gets the
            `ManyRelatedManager` as first argument and must return a filtered QuerySet.
            By default, it returns `all()`
        separator: separator string to join the items with. default: ``", "``
        linkify_item: callable, arguments to reverse() or `True` to wrap items in a ``<a>`` tag.
            For a detailed explanation, see ``linkify`` argument to ``Column``.

    For example, when displaying a list of friends with their full name::

        # models.py
        class Person(models.Model):
            first_name = models.CharField(max_length=200)
            last_name = models.CharField(max_length=200)
            friends = models.ManyToManyField(Person)
            is_active = models.BooleanField(default=True)

            @property
            def name(self):
                return f"{self.first_name} {self.last_name}"

        # tables.py
        class PersonTable(tables.Table):
            name = tables.Column(order_by=("last_name", "first_name"))
            friends = tables.ManyToManyColumn(transform=lambda user: u.name)

    If only the active friends should be displayed, you can use the `filter` argument::

        friends = tables.ManyToManyColumn(filter=lambda qs: qs.filter(is_active=True))

    N, c                    |                     dd            t                      j        |i | ||| _        ||| _        || _        d }t          |          rt          |          }n?t          |t          t          f          rt          |          }n|du rt                      }|.t          dd| j                            di           i|| _        d S d S )	N	orderableF)url)reverse_argsTattrsa )
setdefaultsuper__init__	transformfilter	separatorcallabledict
isinstancetupler
   r   getlinkify_item)	selfr   r   r   r!   argskwargslink_kwargs	__class__s	           g/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/django_tables2/columns/manytomanycolumn.pyr   zManyToManyColumn.__init__2   s     	+u---$)&))) &DN DK"L!! 	!<000KKtUm44 	!L999KKT!!&&K" - [ [DJNN34K4K [{ [ [D #"    c                      t          |          S )zh
        Transform is applied to each item of the list of objects from the ManyToMany relation.
        r   )r"   objs     r'   r   zManyToManyColumn.transformI   s     ~~r(   c                 *    |                                 S )z
        Filter is called on the ManyRelatedManager to allow ordering, filtering or limiting
        on the set of related objects.
        )all)r"   qss     r'   r   zManyToManyColumn.filterO   s    
 vvxxr(   c                 Z   g }|                      |          D ]`}t          |                     |                    }t          | d          r|                     ||          }|                    |           at          t          | j                                      |                    S )Nr!   )contentrecord)	r   r   r   hasattrr!   appendr   r   join)r"   valueitemsitemr/   s        r'   renderzManyToManyColumn.renderV   s    KK&& 	" 	"D()=)=>>Gt^,, J++GD+IILL!!!!+DN;;@@GGHHHr(   c                 J    t          |t          j                  r | di |S d S )Nr   )r   r   ManyToManyField)clsfieldr$   s      r'   
from_fieldzManyToManyColumn.from_fielda   s3    eV344 	!3==== 	! 	!r(   )NNr   N)__name__
__module____qualname____doc__r   r   r   r7   classmethodr<   __classcell__)r&   s   @r'   r   r      s        & &R IM\ \ \ \ \ \.    	I 	I 	I ! ! [! ! ! ! !r(   r   N)	django.dbr   django.utils.encodingr   django.utils.htmlr   r   baser	   r
   r   registerr   r   r(   r'   <module>rH      s          + + + + + + ; ; ; ; ; ; ; ; 0 0 0 0 0 0 0 0 0 0 	[! [! [! [! [!v [! [! [! [! [!r(   