2022-10-28 22:16:23 +02:00
|
|
|
from django.contrib.auth.models import AbstractUser
|
2022-10-29 00:32:18 +02:00
|
|
|
from django.db import models
|
2022-10-28 22:16:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
class User(AbstractUser):
|
|
|
|
pass
|
2022-10-29 00:32:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
class UniquelyNamedModelManager(models.Manager):
|
|
|
|
def get_by_natural_key(self, name: str):
|
|
|
|
return self.get(name=name)
|
|
|
|
|
|
|
|
|
|
|
|
class UniquelyNamedModel(models.Model):
|
2022-10-30 11:09:46 +01:00
|
|
|
name = models.CharField(
|
|
|
|
max_length=100, blank=False, null=False, unique=True, verbose_name="nom"
|
|
|
|
)
|
2022-10-29 00:32:18 +02:00
|
|
|
objects = UniquelyNamedModelManager()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
2022-11-02 23:10:48 +01:00
|
|
|
ordering = ["name"]
|
2022-10-29 00:32:18 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def natural_key(self):
|
|
|
|
return (self.name,)
|
2022-10-30 09:44:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DocumentedModel(models.Model):
|
2022-10-30 11:09:46 +01:00
|
|
|
url = models.URLField(blank=True, null=False, verbose_name="url")
|
2022-10-30 09:44:28 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|