Django datatable and enum
<p>I have a campaign model as follows:</p>

<pre><code>id campaign    objective             platform
1  Hello Word  MOBILE_APP_ENGAGEMENT Facebook
2  Hi There    VIDEO_VIEWS_PREROLL   Twitter
</code></pre>

<p>Model:</p>

<pre><code>class Campaign(Model):
    id = models.TextField(primary_key=True)
    name = models.TextField(default="")
    objective = models.TextField(null=True)
    platform = enumfields.EnumField(Platform, max_length=10, null=True)
</code></pre>

<p>The campaign holds both Twitter and FB campaigns.</p>

<p>The objective field was a free text, but I am not happy with it.</p>

<p>I would like to create 2 different enums (enum34):</p>

<pre><code>class FacebookObjective(Enum):
  MOBILE_APP_ENGAGEMENT
  MOBILE_APP_DOWNLOAD

class TwitterObjective(Enum):
  VIDEO_VIEWS_PREROLL
  TWEET_ENGAGEMENTS
</code></pre>

<p>and somehow use them on the same column. but not sure how to do it.</p>

<p>I thought to use enum, because I need the other uses to use it easily in the code. e.g:</p>

<pre><code>TwitterObjective.VIDEO_VIEWS_PREROLL
</code></pre>

<p>As far as I know (which isn't much where Django is concerned), to make this work you'll need to use a single <code>Enum</code> per field.  So in your case I would put the Twitter or FB designation in the name of the members:</p>

<pre><code>Class Objective(Enum):
    FB_MOBILE_APP_ENGAGEMENT
    FB_MOBILE_APP_DOWNLOAD
    TW_VIDEO_VIEWS_PREROLL
    TW_TWEET_ENGAGEMENTS
</code></pre>

<p>If you really want to use different <code>Enum</code>s you have a couple choices:</p>

<ul>
<li>use nested <code>Enum</code> classes (see <a href="http://stackoverflow.com/a/35886825/208880">http://stackoverflow.com/a/35886825/208880</a>)</li>
<li>use two classes and have your implementation choose between them (which will require either embedding a FaceBook or Twitter code in the name, such as FB_ and TW_, or using unique names across the two <code>Enum</code>s so you can reverse the lookup when going from db to Python)</li>
</ul>

<p><a href="http://stackoverflow.com/a/28842582/208880">This answer</a> may help with the details.</p>

python django enums