Django uses queryset filter save, and an 'queryset' object has no attribute 'Save' error occurs. Solution?

CSDN Q & A 2022-05-15 04:53:40 阅读数:514

djangousesquerysetfilterqueryset

I'm operating py+Django Write a web page , encounter QuerySet filter Of save error .
Error theory ’QuerySet’ object has no attribute ‘save’, In other words, this is a set QuerySet, And for collections , It's not “save” This attribute .

How can I correct it ? thank you

The following is my program code

Models:

Software Table

class Software(models.Model): STATUS_CHOICES = [ (0, ' Planning '), (1, ' In development '), (2, ' In the use '), (3, ' obsolete ') ] name = models.CharField(max_length=100, verbose_name=" System name ") url = models.CharField(max_length=100, verbose_name=" System website ") status = models.PositiveIntegerField(default=0, choices=STATUS_CHOICES, verbose_name=" Current state of ") company = models.ForeignKey(Company, on_delete=models.CASCADE, verbose_name=" Development company or unit ") team = models.ForeignKey(Team, on_delete=models.DO_NOTHING, verbose_name=" Group ") def __str__(self): return self.name

Memo Table

class Memo(models.Model): notes = models.TextField() software = models.ForeignKey(Software, on_delete=models.CASCADE) #software = models.ForeignKey(Software, on_delete=models.SET_NULL, null=True, blank=True) timestamp = models.DateTimeField(default=timezone.now) def __str__(self): return self.notes

Templates:

{% extends 'base.html' %}{% block title %} Audit system {% endblock %}{% block main %}<h2 > Edit notes </h2><hr><form action="/editmemo/" method="POST">{% csrf_token %}<input name="pk" type="hidden" value={
{ target_memo.id }}><table class="table table-striped"> <tr> <td align=right> remarks : </td> <td> {% for memo in memos %} <input type=text name="memos" size=50 value='{
{memo.notes}}'> {% endfor %} </td> </tr> <tr><td> </td><td> <input type=submit value=" Confirm modification " class="btn btn-warning"> </td></tr></table></form>{% endblock %}

View:

@login_required(login_url='/admin/login/')def edit_memo(request,pk=None): logged_user = User.objects.get(username=request.user.username) logged_user = UserProfile.objects.get(user=logged_user) teamid = Team.objects.get(name = logged_user.team).id target_soft = Software.objects.get( id = pk) item = Software.objects.get(id=pk) if request.method=="POST": softwareid = request.POST.get('softwareid') item = Software.objects.get(id=pk) memos = Memo.objects.filter(software=item) #Memo.objects.all().update(notes=memos) print(memos[0]) memos[0].save() return render(request,"showdetail.html",locals()) try: memos = Memo.objects.filter(software=item) except: return redirect("/showall/") return render(request, "edit_memo.html", locals())

Url:

urlpatterns = [ path('editmemo/',views.edit_memo), path('editmemo/<int:pk>/',views.edit_memo), path('', views.index),]+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。 https://primo.wiki/2022/131/202205041351465278.html