Django ForeignKey only delete "child" element - python

I've followed the starting tutorial and my admin page looks like this
I am trying to delete a choice by selecting the "Delete?" option and clicking "Delete", but after doing so it prompts me to delete the entire question and its corresponding choices. How can I only delete individual choices?
I've found that on_delete=models.CASCADE is most likely the culprit, and I've found the alternatives, but none of these seem to just simply remove the Choice and revert the question to the state it was before I added the Choice.
I am a complete beginner and any help is much appreciated.

As Iain Shelvington pointed out,
You have to click "Save" to save changes made to the inlines, including deleting rows. "Delete" deletes the object you are editing, the question in this case
Thank you!

Related

How to use same Choices for all Questions in Django's Polls app

Sub: Django Poll Project.
There can anyone please help me understand to use same set of choices against all questions. I don't want to add choices every time for each question, instead I want to add question with date- time stamp and want that choices which are already added should reflect for my questions and I select any of those choices and vote.
2nd Option I want to work is if I want to add another choice it should allow but it should show all other choices against my question.
Thank You
Rishipal

Option to add extra choices in django form

I am trying to create a model via a form that has multiple other models related to it. Say I have a model Publisher, then another model Article with a foreign key to Publisher. When creating a Publisher via a form, I want to create An article at the same time. I know how to do this via formsets. However, I don't know how to add a button that says add extra article at the same view, without having to be redirected to a new page and losing the old data since the form was not saved. What I want is when someone clicks add new article, for a new form for article to appear and for the user to add a new Article. Is this possible to be done in the same view in django, if so can someone give me and idea how to approach this?
I would show code or my attempts, but I am not sure how to even approach it.
This can only be done using JavaScript. The hard part is to have the management form sync up with the number of rows.
But there's two alternatives:
Semi-javascript (Mezzanine's approach): Generate a ton of rows in the formset and only show one empty. Upon the click of the "add another row" button, unhide the next one. This makes it easier to handle the management form as the unfilled extra's don't need any work.
No fix needed: Add as many rows as is humanly sane. In general, people don't need 40 rows, they get bored with filling out the form or worry that all that work is lost when the browser crashes.
Hope this helps you along. Good luck!

Django Editable Text Field

I've been able to easily create a list of editable items and manage them through the Django admin panel. That seems pretty simple and I have a good idea of how models work from other frameworks.
Although, I'm curious to know to know how I can make something as simple as editing a text area on a static site. Basically, I don't need to "add post" or anything of the sort. I just want to be able to edit a text area on a static site.
Any docs or examples?
I've been looking at packages such as django-flatblocks and chunks, these seem to possibly help with what I'd like to do. I'm just new to the Python world so some of this stuff is a little magic to me, especially involving the administration panel.
One thing that I realized is that these libraries (or apps in django?) seem to be super out of date, stemming back to the last commit being from 2012. Are these still commonly used?
Figured out a solution in case anyone is interested. I ended up using a Django application called django-generic-flatblocks which seems to provide me with what I need. Although, it's a bit strange as I had to replace all the text on my site with a gblock and then re-enter it all. Seems as if upon first creation of a block, it's empty so you essentially have to provide it with a value.
After that, if you log into the admin panel you're able to pull up the block and edit it. Alternatively, if you're logged into the Admin panel you're able to view your site and an edit tag is provided and you'll go directly to that block in the admin panel.
If anyone knows of anything which essentially allows me to define the text blocks up front in the admin panel then add the tags to the code, please lmk. I'd prefer to load all my content into the admin panel first and then just throw the tag into the code and have it display. That would save a lot of time in terms of having to copy the existing content, store it away, adding the tag, and then having to put it back in.
This seemed to be the only one of the recommended apps that worked for me. I tried to use Chunks because this really is only for title/text but on Django 1.11 it would freak out on me about not having South.db, which isn't even used.
https://github.com/bartTC/django-generic-flatblocks

Customizing admin-site: delete_selected

I'm working on recreating the admin site to match the theme of the current website and it's been fine up till now, but when I try to select multiple users and use the "delete selected users" action nothing happens.
I have a bit of code, so I have it pasted here
The button is called in admin/actions.html on line 4.
From reading the admin-site's source I was able to find the method delete_selected in admin/actions.py.I have only been copying and pasting tags from the original admin-site templates to fit my new ones with the site's style, so I can't figure out why the method isn't being passed.
Here's apicture of the finished page, where everything works except that Go button.
I feel like there might be a way to recreate a template tag to do it for me but I'm not sure what to call or how ?
The check boxes each have the object's ID as values but I'm not sure why it's not being passed to the 'go' button there.
Sorry, it was the simplest thing. I forgot to include the form surrounding the table. I hope this question will be helpful to anyone looking to customize the admin-site in the future.
Thanks!

Forms generated through admin in Django

I need to be able to create forms from admin panel. Process would look like this:
I click on "Add form" then I enter email to which the form should be sent and of course several fields (probably thanks to inlines) consisting of field name, type and if it is required. User should be able to view and fill the form and submit it and the data should be sent to the email given in admin.
Everything looks pretty straightforward but from my point of view it need some metaclass programming skills.
Could anyone point me to a goot form builder for Django or at least hand some tips about creating such thing? I found django-forms-builder but it is a bit too restricted imho.
I know this one's a few months old but I just though I'd post an update here anyway for anyone else that comes along.
django-forms-builder has just been rewritten to do exactly what you were looking for when you originally posted this question.
You can find the new version at http://github.com/stephenmcd/django-forms-builder or http://bitbucket.org/stephenmcd/django-forms-builder
There are many alternatives, although not many of them are actively maintained:
https://www.djangopackages.com/grids/g/form-builder/
If you want to have a full control of what's happening (change fields for your needs or add new ones, add captcha or honeypot, add custom handling of form data, use form wizards or even use your forms via web REST API), use django-fobi https://pypi.python.org/pypi/django-fobi

Categories