lundi 2 février 2015

Django - dynamic text in admin form


Vote count:

0




I am new to django and have an app which allows an admin to create surveys and am trying to find a way for the admin to include text inside of the form (when creating a survey) which will represent a field value they have entered earlier in the form


example: say the admin wants to refer to the name of the survey in the survey description or inside of the question, but doesnt want to type the name of the survey and instead a keyword which refers to the survey name field and properly renders the name of the survey in html


models.py:



class Survey(models.Model):
name = models.CharField(max_length=200)
slug = models.SlugField(max_length=255)
description = models.TextField()
pub_date = models.DateTimeField(auto_now=False, default=datetime.datetime.now)
external_survey_url = models.CharField(max_length=255, blank=True)
minutes_allowed = models.FloatField(max_length=10, default=0)
is_active = models.BooleanField(default=True)


admin.py:



class SurveyAdmin(admin.ModelAdmin):
save_as = True
prepopulated_fields = { "slug": ("name",),}
fields = ['name', 'pub_date', 'description', 'external_survey_url', 'minutes_allowed', 'slug']
inlines = [QuestionInline, SurveyImageInLine]


I have tried using {{ var|safe }}, but found this only applies to html and not django template language variables otherwise the admin could simply fill in {{ var }} when they are creating the object in admin, hope I have been clear enough. Thanks in advance!



asked 1 min ago







Django - dynamic text in admin form

Aucun commentaire:

Enregistrer un commentaire