---
title: "Mionsamhail _meta API"
version: 5.2
locale: ga
source: https://docs.djangoproject.com/ga/5.2/ref/models/meta/
canonical: https://djangodocs.dev/ga/5.2/ref/models/meta/
---
# Mionsamhail `_meta` API

#### `class Options`

Tá an tsamhail `_meta` API ag croílár an ORM Django. Cuireann sé ar chumas codanna eile den chóras mar chuardaigh, ceisteanna, foirmeacha agus an riarachán cumais gach samhail a thuiscint. Tá an API inrochtana trí thréith `_meta` gach aicme samhail, ar shampla é de réad `Django.db.Models.Options.Options`.

Methods and attributes that it provides can be used to:

- Aisghabháil gach cás réimse de mhúnla
- Aisghabháil sampla réimse amháin de mhúnla de réir ainm
- Retrieve all fields that compose the primary key of a model

## API rochtana allamuigh

### Sampla réimse amháin de mhúnla a aisghabháil de réir ainm

#### `Options.get_field(field_name)`

Tugann ainm réimse ar ais.

Is féidir le field\_name\` a bheith ina ainm réimse ar an tsamhail, réimse ar mhúnla teibí nó oidhreachta, nó réimse atá sainmhínithe ar mhúnla eile a thugann in iúl don tsamhail. Sa chás deireanach sin, is é an field\_name\` (in ord rogha) an:attr: ~.foreignkey.related\_query\_name a shocraíonn an t-úsáideoir, an:attr: ~.foreignKey.related\_name atá leagtha amach ag an úsáideoir, nó an t-ainm a ghineann Django go huathoibríoch.

[`Hidden fields`](/ga/5.2/ref/models/fields/#django.db.models.Field.hidden) cannot be retrieved
by name.

Mura bhfaightear réimse leis an ainm a thugtar a:class: ~django.core.exceptions.fieldDoesNotExist ardófar eisceacht.

```pycon
>>> from django.contrib.auth.models import User

# A field on the model
>>> User._meta.get_field("username")
<django.db.models.fields.CharField: username>

# A field from another model that has a relation with the current model
>>> User._meta.get_field("logentry")
<ManyToOneRel: admin.logentry>

# A non existent field
>>> User._meta.get_field("does_not_exist")
Traceback (most recent call last):
    ...
FieldDoesNotExist: User has no field named 'does_not_exist'
```

### Aisghabháil gach cás allamuigh de mhúnla

#### `Options.get_fields(include_parents=True, include_hidden=False)`

Tugann sé cúpla réimsí a bhaineann le samhail ar ais. Glacann get\_fields () le dhá pharaiméadar is féidir a úsáid chun na réimsí a chuirtear ar ais a rialú:

**include\_tuismitheoirí \`\`**

  `True` de réir réamhshocraithe. Cuimsíonn sé go réimsí atá sainithe ar ranganna tuismitheoirí Má tá sé socraithe ar `False`, ní chuardóidh get\_fields () ach réimsí a dearbhaíodh go díreach ar an tsamhail reatha. Meastar go bhfuil réimsí ó mhúnlaí a dhéanann oidhreacht go díreach ó mhúnlaí teibí nó ó ranganna seachfhreastalaí áitiúla, ní ar an

**`include_hidden`**

  `False` de réir réamhshocraithe. \<django.db.models.Field.hidden\>Má tá sé socraithe go `True`, beidh get\_fields () san áireamh: attr: réimsí i bhfolach .

```pycon
>>> from django.contrib.auth.models import User
>>> User._meta.get_fields()
(<ManyToOneRel: admin.logentry>,
 <django.db.models.fields.AutoField: id>,
 <django.db.models.fields.CharField: password>,
 <django.db.models.fields.DateTimeField: last_login>,
 <django.db.models.fields.BooleanField: is_superuser>,
 <django.db.models.fields.CharField: username>,
 <django.db.models.fields.CharField: first_name>,
 <django.db.models.fields.CharField: last_name>,
 <django.db.models.fields.EmailField: email>,
 <django.db.models.fields.BooleanField: is_staff>,
 <django.db.models.fields.BooleanField: is_active>,
 <django.db.models.fields.DateTimeField: date_joined>,
 <django.db.models.fields.related.ManyToManyField: groups>,
 <django.db.models.fields.related.ManyToManyField: user_permissions>)

# Also include hidden fields.
>>> User._meta.get_fields(include_hidden=True)
(<ManyToOneRel: auth.user_groups>,
 <ManyToOneRel: auth.user_user_permissions>,
 <ManyToOneRel: admin.logentry>,
 <django.db.models.fields.AutoField: id>,
 <django.db.models.fields.CharField: password>,
 <django.db.models.fields.DateTimeField: last_login>,
 <django.db.models.fields.BooleanField: is_superuser>,
 <django.db.models.fields.CharField: username>,
 <django.db.models.fields.CharField: first_name>,
 <django.db.models.fields.CharField: last_name>,
 <django.db.models.fields.EmailField: email>,
 <django.db.models.fields.BooleanField: is_staff>,
 <django.db.models.fields.BooleanField: is_active>,
 <django.db.models.fields.DateTimeField: date_joined>,
 <django.db.models.fields.related.ManyToManyField: groups>,
 <django.db.models.fields.related.ManyToManyField: user_permissions>)
```

### Retrieving fields composing the primary key of a model

> **New in Django 5.2**

#### `Options.pk_fields`

Returns a list of the fields composing the primary key of a model.

When a [`composite primary key`](/ga/5.2/ref/models/fields/#django.db.models.CompositePrimaryKey)
is defined on a model it will contain all the
[`fields`](/ga/5.2/ref/models/fields/#django.db.models.Field) referenced by it.

```python
from django.db import models

class TenantUser(models.Model):
    pk = models.CompositePrimaryKey("tenant_id", "id")
    tenant_id = models.IntegerField()
    id = models.IntegerField()
```

```pycon
>>> TenantUser._meta.pk_fields
[
    <django.db.models.fields.IntegerField: tenant_id>,
    <django.db.models.fields.IntegerField: id>
]
```

Otherwise it will contain the single field declared as the
[`primary key`](/ga/5.2/ref/models/fields/#django.db.models.Field.primary_key) of the model.

```pycon
>>> User._meta.pk_fields
[<django.db.models.fields.AutoField: id>]
```
