The idea is to choose from a select few contenttypes and then add a key, and the resulting config will trigger a bunch of services. However whenever I save the form, the contenttype stored in the app_model is always None, which is clearly undesirable.
This is in Django1.8
Here is the admin:
class ContentTypeModelChoiceField(ModelChoiceField):
def label_from_instance(self, obj):
return "{}-{}".format(obj.app_label, obj.model)
class MyConfigForm(ModelForm):
class Meta:
model = models.MyConfig
fields = '__all__'
def __init__(self, *args, **kwargs):
super(MyConfigForm, self).__init__(*args, **kwargs)
self.fields['app_model'].label = "App Name"
app_model = ContentTypeModelChoiceField(
ContentType.objects.filter(
app_label__startswith='myApp',
model="myModel",
),
empty_label="Choose a model",
)
class MyConfigAdmin(admin.ModelAdmin):
model = models.MyConfig
form = MyConfigForm
list_display = (<display fields>
)
search_fields = (<search fields>
)
And here is the model itself:
class MyConfig(models.Model):
app_model = models.ForeignKey(ContentType, null=True)
ref_key = models.CharField(max_length=32, null=True)