I'm building a webpage that use ModelForm with ManyToMany relations. The Admin of django has the useful RelatedFieldWidgetWrapper. It creates a + next to relationfields that, when pressed, opens a popup to create a related-object. Once the creation is made the main webpage (the one where we press the +) has the new item loaded.
Now, in my website I would like to have something similar, my questions are:
is it correct to use the RelatedFieldWidgetWrapper in a webpage outside admin?
how does the page autoloads the new content (this is mainly my curiosity)
any other applicable solution to have a handy form without requiring complex JS or several pages?
thanks
Related
I am trying to develop a website where I can see the homepage as it is from Django admin panel. The reason I want that is I want to edit the name of the static content like 'Home' to 'All' along with the change of slide show picture. In summary, I want to change the website layout from Django admin panel that is not accessible to users. Is that possible? I just want an idea of how to implement the process.
Static texts you can change in admin panel with different modules:
for example django-rosetta or my own library Django-tof. https://github.com/wP-soft-GmbH/django-tof
But in your case, i think, you want to made something more.
For this case you can use django-flat-pages, already included in Django, if you have a static web-page.
you can edit every element on the page and after save, you can see it on the front.
if you really want to change the django templates, which you use in your views, you can create a simple template editor in the admin panel based on a widget like django-Ckeditor.
I have a stackedinline Django admin. This is used to add multiple products for a shop. However, when I click on 'Save and add another' it sometimes shows 'Entity too large', even when the files are below the allowed size, or sometimes it shows 'DATA_UPLOAD_MAX_NUMBER_FIELDS' error. My question is, does Django stackedinline admin save each and every object each time we click on save? If no, then what could be the reason for this error?
StackedInline is saved only when you click on main save.
It does save all through building the formsets and it does not use ajax requests for each of the rows -> source
Also you can easily check this by inspecting and opening network tab
I'm totally new to Mezzanine CMS. I got handed a site to work with and so far I've been able to do all the changes without problem. I've run across a problem in which they want a new section in the home page. I go to the admin section to edit the home page, but there is no extra content field.
On the home page, I see 4 sections "content" "priorities" "testimonials" and "clients". I would like to have another "content" area as a 5th section. How do I go on and add this section? I'm totally new to Django but would be appreciative if someone could explain or point in the right direction.
Here is a link to an image for reference.
https://imgur.com/a/sUKOtvS
Thanks in advance
The homepage content would be backed by a Django model with attributes for the partners and testimonial fields. You'll need to find the Python class for this model in your code base (you could search for those field names), and you'll need to add a new attribute for the new section you need.
Django and Mezzanine have lots of different field types you can use for these attributes, so consult their respective documentation for how those work (Django's are a lot more comprehensive, so start there).
Once you've done that, you'll need to create a database migration for the new attribute - that adds the field to the database table that will store the actual content, again consult the Django documentation for how these work.
Finally you may need to add the new field to the Admin class, which is the Python class (similar to the model) that controls which fields appear in the admin interface, and how they appear. I say "may" as these generally appear automatically without any code, but if things have been modified to a certain extent, you may need to do this manually.
Recently I started using Django CMS, it turns out to be a great tool for web developer. But one thing I couldn't have achieved so far is creating a form for users so they could submit some content created with WYSIWYG editor. I thought maybe there's some easy way to add editor available in admin panel (the one you use with creating / modifying Text plugins), doesn't seem like that unfortunately.
Long story short - I'd like to enbable users to use the same WYISWYG editor available from admin panel, without giving them permission to access admin panel. Is it possible? Or do I have to use some additional extension so I could embed similiar editor on my Page(s)?
Maybe you should look into divio/djangocms-text-ckeditor. It offers a HTMLFieldto be parts of models and a TextEditorWidgetto be parts of your app's forms.
So based on the comments I assume, when you say "users", you mean anonymous site visitors that are not registered to the CMS? And you want to display a WYSIWYG form field to them to "submit some content"?
If my assumptions are correct, you just need to create an own plugin or maybe an app.
See http://docs.django-cms.org/en/release-3.4.x/how_to/custom_plugins.html
I've started one new django project. I've linked the HTML file in the django's admin page. When I click view site in the admin page the html file has open.
In this html file there is a register button. When I click it, the html form will open for fill the details to register for signup.
When I filled the details and click submit button, the python file (signup.py) has to show the data and save in db. But I got the error
"Page not found (404)
Request Method: GET
Request URL: http://10.95.228.84:8000/signup.py?CID=aasa&user_name=sadsad&User_email=sasa%40gmail.com&DOB1=2016-08-30&Password11=sasasa&Password12=sasasa&submit=submit"
Please let me know how to link this signup.py file with this html.
What's going on is that you have a GET request to a URL that happens to be named 'signup.py' followed by the form parameters. This is not how Django fundamentally operates. Django forms automatically 'takes care of' saving new entries into the database if the forms are valid (assuming you are using a correct model and ModelForms).
I can't tell what your models are like or your urls, but I would suggest:
1) Creating Models in models.py that accurately match what you are trying to save into your database (if you haven't already)
2) Creating a view in views.py and that will link to a template (that you will need to create) displaying the data that is being saved into your database
3) Creating a url for this new view you created in urls.py
4) Editing the view that is currently handling the signup form to redirect your your view if the form is valid.
I would suggest looking at the Django tutorial. Going through it once or twice will solidify the basic workflow of using Django. This tutorial also has a solid tutorial on simple forms.
Django Tutorial
Simple Django Forms