0

I want to manage a dictionary inline over the admin interface. These are my models. What I got working is of course a separated management of request and dictionary. But I want to add key value pairs in the request admin interface with a TabularInline. Do I have to skip the dictionary in some way or what do I have to do?

class Dictionary(models.Model):
    name = models.CharField(max_length=255)

class KeyValuePair(models.Model):
    container = models.ForeignKey(Dictionary, db_index=True)
    key = models.CharField(max_length=240, db_index=True)
    value = models.CharField(max_length=240, db_index=True)

class Request(models.Model):
    params = models.ForeignKey(Dictionary, related_name="params_map", blank=True, null=True)
Sven Mäurer
  • 715
  • 1
  • 9
  • 19

1 Answers1

0

Have you tried django-jsonfield?: https://github.com/bradjasper/django-jsonfield

..I think that this would display a textarea in the admin area (that would enable you to write raw JSON - though this field allows you to access it as a dict in your Python), but you could probably create a custom widget for the admin area to override this: https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides

Chris Berragan
  • 141
  • 1
  • 3
  • It's not completely what I want but a first step. Do you know how I can display a json in the template language? – Sven Mäurer Jan 26 '15 at 15:12
  • I think that you should be able to access it as if it was a Python dictionary: http://stackoverflow.com/questions/1275735/how-to-access-dictionary-element-in-django-template – Chris Berragan Jan 27 '15 at 16:22