Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed some ideas how to make delete (BooleanField) in Django
    primarykey
    data
    text
    <p>I'm trying to do this: in my web site, I have some data from database, like this:</p> <pre><code>Math 140 Math 141 CS 320 CS 240 </code></pre> <p>And I want to do it like this: When you check box and than press delete, this subject gets deleted from database.</p> <pre><code>Math 140 [] Math 141 [] CS 320 [] CS 240 [] </code></pre> <p>template.html</p> <pre><code> &lt;div id="subjects-list"&gt; {% if user.username %} &lt;ul&gt; {% if subjects %} {% for subject in subjects %} &lt;li&gt;{{ subject.name }} {% endfor %} {% else %} No Subjects for this user {% endif %} &lt;/ul&gt; {% else %} You are in else {% endif %} &lt;/div&gt; </code></pre> <p>models.py</p> <pre><code>class Subjects(models.Model): """ Subject Database """ name = models.CharField(max_length=64, unique=False) #Subject Names on left-menu user = models.ForeignKey(User, unique=False) def __unicode__(self): return '%s %s' %(self.name, self.user.username) </code></pre> <p>views.py</p> <pre><code>@login_required def user_page(request, username): user = get_object_or_404(User, username=username) ''' Form in the left-menu to create a new subject ''' if 'subject-create-b' in request.POST: subject_form = SubjectCreationForm(request.POST) if subject_form.is_valid(): subject = Subjects.objects.get_or_create(name = subject_form.data['name'], user = user) return HttpResponseRedirect('.') # redirect to the same page # later have to be substituted with AJAX else: subject_form = SubjectCreationForm() # Filter Subjects table by currently logged in user subjects = Subjects.objects.filter(user__exact = user) return render_to_response('user_page.html', {'subject_creation_form': subject_form, 'subjects': subjects, 'user': request.user, }, context_instance=RequestContext(request)) </code></pre> <p>So my question is basically how can I do this?</p> <p>Do I need to add new form and than put it right after the "<li>{{ subject.name }}". If yes, how do I know that this particular box have to delete this particular data object?</p> <p>Or do I need to add some new column to mymodels, and than if check box is checked - switch this column to true and than in views delete all rows that have true in new column.</p> <p>Or may be you can suggest some better techique. Thank you in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload