Git Product home page Git Product logo

Comments (8)

akx avatar akx commented on July 17, 2024 1

The correct syntax for enumfields.Enum labels is

    class Labels:
        RED = 'A custom label'

instead of

    labels = {
        RED: 'A custom label'
    }

as you seem to be using.

from django-enumfields.

akx avatar akx commented on July 17, 2024 1

class Labels, not class labels or class levels.

from django-enumfields.

auvipy avatar auvipy commented on July 17, 2024

from django_enumfield import enum
from adminsortable.models import Sortable, SortableForeignKey

from django.db import models
from django.template.loader import get_template

class LandingTemplate(enum.Enum):
DEFAULT = 0

labels = {
    DEFAULT: 'Default Landing Template',
}

class SMSTemplate(enum.Enum):
DEFAULT = 0

labels = {
    DEFAULT: 'Default SMS Template',
}

class EmailTemplate(enum.Enum):
DEFAULT = 0
BLANK = 1

labels = {
    DEFAULT: 'Default Email Template',
    BLANK: 'Blank Email Template',
}

VIDEO_TEMPLATE_CHOICES = (
(
'Stupeflix',
(
('default', 'Stupeflix Default'),
('mylead', 'Stupeflix MyLead'),
)
),
(
'Idomoo',
(
('idomoo_mylead1', 'Idomoo My Lead 1'),
('idomoo_myride1', 'Idomoo My Ride 1'),
)
)
)

class CampaignType(Sortable):
CATEGORY_CHOICES = (
('myride', 'My Ride'),
('mylead', 'My Lead'),
('mycustomer', 'My Customer'),
('myshow', 'My Showroom'),
)

COLOR_CHOICES = [
    ('FF0000', 'Red'),
    ('FFAA00', 'Orange'),
    ('FFFF00', 'Yellow'),
    ('91C43B', 'Green'),
    ('0000FF', 'Blue'),
    ('00FFFF', 'Purple'),
]

# Basic
name = models.CharField(max_length=64, unique=True)
category = models.CharField(
    max_length=64,
    choices=CATEGORY_CHOICES,
    null=True,
    blank=True,
    db_index=True,
)

mask = models.ForeignKey(
    'gallery.Mask',
    null=True, blank=True,
    on_delete=models.CASCADE,
)

# Templates
landing_template = enum.EnumField(
    LandingTemplate,
    default=LandingTemplate.DEFAULT,
)
sms_template = enum.EnumField(SMSTemplate, default=SMSTemplate.DEFAULT)
email_template = enum.EnumField(
    EmailTemplate,
    default=EmailTemplate.DEFAULT,
)

video_template = models.CharField(
    max_length=128,
    default='default',
    choices=VIDEO_TEMPLATE_CHOICES,
)

# Photo taking parameters in the mobile application
min_count = models.PositiveSmallIntegerField(default=0)
max_count = models.PositiveSmallIntegerField(default=6)
default_count = models.PositiveSmallIntegerField(default=4)

color = models.CharField(
    max_length=16, choices=COLOR_CHOICES,
    blank=True, null=True
)

class Meta:
    verbose_name = 'campaign type'
    verbose_name_plural = 'campaign types'

def __str__(self):
    return self.name

@property
def landing_template_name(self):
    return LandingTemplate.name(self.landing_template).lower()

def render(self, prefix, context={}):
    fields = {
        'sms': 'sms_template',
        'email': 'email_template',
        'landing': 'landing_template',
    }
    if prefix not in fields:
        raise ValueError('Prefix {} is not allowed'.format(prefix))
    field_name = fields[prefix]
    template_name = self._meta.get_field(field_name)\
        .enum.name(getattr(self, field_name)).lower()
    template = get_template('{}/{}.jinja'.format(prefix, template_name))
    return template.render(context)

class CampaignTypeImage(Sortable):
type = SortableForeignKey('campaigns.CampaignType', related_name='images')
name = models.SlugField(max_length=24, help_text='Internal name.')
title = models.CharField(max_length=24, help_text='Human-readable name.')

class Meta(Sortable.Meta):
    unique_together = [
        ('type', 'name'),
        ('type', 'title'),
    ]

def __str__(self):
    return self.title

from django-enumfields.

auvipy avatar auvipy commented on July 17, 2024

thanks!! the old developer did that!

from django-enumfields.

auvipy avatar auvipy commented on July 17, 2024

after changing to the suggested changes i got the following error TypeError: int() argument must be a string, a bytes-like object or a number, not 'type'

class LandingTemplate(enum.Enum):
DEFAULT = 0

class labels:
    DEFAULT = 'Default Landing Template'

class SMSTemplate(enum.Enum):
DEFAULT = 0

class labels:
    DEFAULT = 'Default SMS Template'

class EmailTemplate(enum.Enum):
DEFAULT = 0
BLANK = 1

class levels:
    DEFAULT = 'Default Email Template'
    BLANK = 'Blank Email Template'

from django-enumfields.

auvipy avatar auvipy commented on July 17, 2024

updated codes https://pastebin.ubuntu.com/p/YkQDx6xhpH/ and trackeback https://pastebin.ubuntu.com/p/2N2BnMpTmf/ what I am doing wrong

from django-enumfields.

akx avatar akx commented on July 17, 2024

from django_enumfield import enum

I only just noticed you're not even using this project. This project's module is called enumfields, not django_enumfield.

from django-enumfields.

auvipy avatar auvipy commented on July 17, 2024

yup, i fixed it by noticing that as well!

from django-enumfields.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.