I have some models in Django like this:
class Object(models.Model):
...
class ObjectFeatures(models.Model):
class Meta:
unique_together = (('object', 'feature'),)
count = models.PositiveSmallIntegerField()
object = models.ForeignKey(...)
feature = models.ForeignKey(...)
class Feature(models.Model):
is_number = models.BooleanField()
...
I have an object, and in this object is an inline form in the admin panel with ObjectFeature
. There you can select the feature you want to add from features, and the count of how many of that feature are available.
The is_number
defines if the feature expects a number or, if false, a boolean (0 or 1 in count).
Is there anyway to display a checkbox in the TabularInline
when it expects a boolean rather than an integer, though it's an IntegerField
?
Another possibility is to define a boolean and an integer field in object_features
. Is there a possibility I can show just one of those, based on the value in is_number
?
In admin.py:
class ObjectFeatureInline(admin.TabularInline):
model = ObjectFeature
can_delete = True
verbose_name_plural = 'Object features'
class ObjectAdmin(admin.ModelAdmin):
inlines = (ObjectFeatureInline,)
...