New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation for use of layout with ModelForm #1018
Comments
Hi @patagoniapy Thanks for your message. From a quick look I agree there isn't anything specific on model forms. Here is a SO answer which gives some information. https://stackoverflow.com/a/13201588/12482183 If you have a suggestion on how to improve the documentation that would be great. 👍 |
I now you're very busy, but could you just briefly explain the differences between setting layout in the class Book(model.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey('author.name', on_delete=models.CASCADE)
publisher = models.CharField(max_length=100) I can create a model form: from .models import Book
class BookForm(forms.ModelForm):
class Meta:
model = Book
fields = ['title', 'author', 'publisher'] Now that the ModelForm is built, how could I for example set CSS, placeholder text, etc? Once I understand this process, I wouldn't mind writing some ModelForm tutorials and/or examples for the documentation! |
I actually just figured it out. When I have some examples ready, what is the best way to submit those for inclusion in the |
I'm glad you worked it out 👍 The best way to propose some changes is via a pull request. The docs (which are hosted on rtd) are in this repo under the docs folder. You can build them locally by running the There are some notes in the contributing section of the docs which may help. Good luck. |
@patagoniapy how did you figure it out? I have followed the referenced SO answer, looked at all the docs I can find, and I still find my helper/layout is being completely ignored. my set up (none of the css classes are being applied anywhere on my form):
My form
My template
My view
|
From a quick glance in your template you need to render the form using the crispy template tag. So {{ form }} becomes {% crispy form %} Will also need to load the tag in your template. See - https://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_forms.html Hope this helps. |
@smithdc1 omg thank you i had gotten all confused reading the docs because |
Glad it worked for you. Good luck with your project. 👍 |
Is there any documentation on use of
crispy_forms.layout
with ModelForms?I would love to help write some examples and documentation for it, but can't seem to find any existing documentation or examples on customizing layout of model forms.
The text was updated successfully, but these errors were encountered: