-4

I want to be able to set a variable in the django admin panel, which will be passed to the template as template variable, similar to placeholder in cms. (For example when I save this variable in admin panel it will be rendered to the template)

Added.

Let's say I have a site page with text area, this text area I can replace by template variable in view with template tags {{ text }}. But I want to do it in the django admin panel, what i did was creating the model with text field, registering it in admin panel and replacing only one row in this table and geting this text variable in view that I want to pass in to the template as text_home = Text_home_page.objects.all()[0].text.

I think that creating whole table to modify only one template variable is not a good idea.

I found a similar question but i dont know how to implement it.

Eugene Primako
  • 2,767
  • 9
  • 26
  • 35
Popka
  • 63
  • 8

1 Answers1

0

Your question is not very clear, are you referring to a default value, if you are you can easily create a default value argument to your model field, or you can create a new field to store a default value, then you can set a condition to use the default value if the actual value is empty

this might not be a good practice but I hope you can edit your question to make it clearer, and add a code sample of what you might have tried to do

maroof shittu
  • 2,027
  • 1
  • 11
  • 14
  • yes creating a whole table(model) to edit one context variable is indeed a bad idea, if the field is related to any model on the page (like meta information), you can add a meta field to the model, and you can edit this field from the model I don't think Django is wired for you to pass a variable straight from the admin to a template, but my knowledge in the django admin is limited. it is typically meant for you to create and edit models, so you might need to do all the work inside your django template – maroof shittu Dec 23 '17 at 10:25