1๐
You should take a look at the Django Model Form documentention, especially the providing initial values part.
From the docs :
class Article(models.Model):
headline = models.CharField(max_length=200, null=True, blank=True,
help_text="Use puns liberally")
content = models.TextField()
class ArticleForm(ModelForm):
class Meta:
model = Article
>>> article = Article.objects.get(pk1=)
>>> article.headline
'My headline'
>>> form = ArticleForm(initial={'headline': 'Initial headline'), instance=article)
>>> form['pub_date'].value()
'Initial headline'
๐คThe Django Ninja
0๐
You can pass initial data for the admin form using the GET parameters. For example:
/admin/app/person/add/?name=some+name&surname=surname&address=some+street
will open Person
creation form with prepopulated fields.
๐คcatavaran
- [Answer]-How to have next and previous links on a webpage in django:
- [Answer]-Django โ how to create duplicate apps without duplicating the code (models, signals and so on)
- [Answer]-Django ModelForm: Making an "Other" Textarea manditory when the user selects "Other" from RadioSelect
- [Answer]-In Django, how to use a manager as default but not for related fields?
- [Answer]-Running commands with django-extensions
0๐
Django got your back. Check out form.initial
form = YourForm(intial={'name': name ...} )
Then you can render the form manually in your template.
๐คMartol1ni
Source:stackexchange.com