Comments (8)
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.
class Labels
, not class labels
or class levels
.
from django-enumfields.
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.
thanks!! the old developer did that!
from django-enumfields.
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.
updated codes https://pastebin.ubuntu.com/p/YkQDx6xhpH/ and trackeback https://pastebin.ubuntu.com/p/2N2BnMpTmf/ what I am doing wrong
from django-enumfields.
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.
yup, i fixed it by noticing that as well!
from django-enumfields.
Related Issues (20)
- Drop Python2 compatibility HOT 4
- Add blurb about included enumeration types in Django 3.0? HOT 4
- Automatically register EnumFieldListFilter
- New release on PyPI HOT 2
- Customize enum choices in serializer HOT 2
- 2.1.0 Incompatibility with drf-yasg HOT 2
- DRF : Object of type Gender is not JSON serializable when calling OPTIONS request HOT 1
- Limit choices of an enum HOT 2
- Migrate to new CI platform HOT 5
- Python 3.11 Support HOT 1
- Allow to serialize enum by names HOT 2
- Breaks with django 2.0 HOT 4
- Calculate max_length automatically? HOT 2
- Deprecation warning in Django 2.1.1 HOT 2
- Support Field attributes (like 'name', etc) HOT 1
- Accept subset of the Enum values HOT 2
- Incompatibility with django-filter HOT 1
- Is the project alive? HOT 13
- Includes tests in source tarball
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-enumfields.