# Path: courriers/settings.py
# ALLOWED_LANGUAGES = getattr(settings, "COURRIERS_ALLOWED_LANGUAGES", settings.LANGUAGES)


import os
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.template.defaultfilters import slugify, truncatechars
from django.utils.translation import gettext_lazy as _
from django.utils import timezone as datetime
from django.urls import reverse
from django.db.models.query import QuerySet
from courriers.settings import ALLOWED_LANGUAGES
    fname, ext = os.path.splitext(filename)
    filename = "{}{}".format(slugify(truncatechars(fname, 50)), ext)

    return os.path.join("courriers", "uploads", filename)


class NewsletterList(models.Model):
    name = models.CharField(max_length=255)
    slug = models.SlugField(max_length=255, unique=True)
    description = models.TextField(blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    list_id = models.IntegerField(null=True)

    class Meta:
        abstract = True

    def __str__(self):
        return self.name or ""

    def get_absolute_url(self):
        return reverse("newsletter_list", kwargs={"slug": self.slug})


class NewsletterSegment(models.Model):
    name = models.CharField(max_length=255)
    segment_id = models.IntegerField()
    newsletter_list = models.ForeignKey(
        "courriers.NewsletterList", on_delete=models.PROTECT, related_name="lists"
    )
    lang = models.CharField(

# Path: courriers/settings.py
# ALLOWED_LANGUAGES = getattr(settings, "COURRIERS_ALLOWED_LANGUAGES", settings.LANGUAGES)


# Path: courriers/base_models.py
import os
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.template.defaultfilters import slugify, truncatechars
from django.utils.translation import gettext_lazy as _
from django.utils import timezone as datetime
from django.urls import reverse
from django.db.models.query import QuerySet
from courriers.settings import ALLOWED_LANGUAGES

    fname, ext = os.path.splitext(filename)
    filename = "{}{}".format(slugify(truncatechars(fname, 50)), ext)

    return os.path.join("courriers", "uploads", filename)


class NewsletterList(models.Model):
    name = models.CharField(max_length=255)
    slug = models.SlugField(max_length=255, unique=True)
    description = models.TextField(blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    list_id = models.IntegerField(null=True)

    class Meta:
        abstract = True

    def __str__(self):
        return self.name or ""

    def get_absolute_url(self):
        return reverse("newsletter_list", kwargs={"slug": self.slug})


class NewsletterSegment(models.Model):
    name = models.CharField(max_length=255)
    segment_id = models.IntegerField()
    newsletter_list = models.ForeignKey(
        "courriers.NewsletterList", on_delete=models.PROTECT, related_name="lists"
    )
    lang = models.CharField(

        max_length=10, blank=True, null=True, choices=ALLOWED_LANGUAGES