Opciones de Campos
Tipos de Campos
- AutoField
- BigAutoField 1 a 9’223,372’036,854’775,807
- BigIntegerField -9’223,372’036,854’775,808 a 9’223,372’036,854’775,807
- BinaryField
- BooleanField
- CharField
- DateField auto_now, auto_now_add
- DateTimeField auto_now, auto_now_add
- DecimalField max_digits, decimal_places
- DurationField
- EmailField
- FileField upload_to, storage
- FilePathField path, match, recursive, allow_files, allow_folders
- FloatField
- GeneratedField expression, output_field, db_persist
- GenericIPAddressField protocol, unpack_ipv4
- ImageField upload_to, height_field, width_field
- IntegerField -2147483648 a 2147483647
- JSONField encoder, decoder
Campos Relacionales
- ForeignKey to, on_delete, limit_choices_to, related_name, related_query_name, to_field, db_constraint, swappable
- ManyToManyField to, related_name, related_query_name, limit_choices_to, symmetrical, through, through_fields, db_table, db_constraint, swappable
Modelos
from django.db import models
from django.urls import reverse
class MiModelo(models.Model):
# campos
def get_absolute_url(self):
return reverse("nombre_vista_detalle", kwargs={"pk": self.pk})