django-models

Django Edit Profile - 'bool' object is not callable

非 Y 不嫁゛ 提交于 2021-02-10 18:31:44
问题 So I just followed this tutorial to create a profile for a user and allow them to edit it but I get this error when I go and visit the edit page 'bool' object is not callable File "C:\Users\...\account\userprofile\views.py", line 64, in profile_edit_view if request.user.is_authenticated() and request.user.id == user.id: TypeError: 'bool' object is not callable models.py: from django.db import models from django.contrib.auth.models import User from django.db.models.signals import post_save

How to filter a Generic ListView?

久未见 提交于 2021-02-10 16:48:54
问题 I am using a CBV ListView , The problem is, the view returns a list of ALL notes on the system. What I would really prefer is for the list to only return the 'notes' that are associated with a particular CandProfile (model) The notes model is : class CandidateNote(models.Model): candidate = models.ForeignKey(CandProfile, on_delete=models.CASCADE, related_name='candidatenotes_cand') note_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL, related_name=

How to filter a Generic ListView?

馋奶兔 提交于 2021-02-10 16:48:07
问题 I am using a CBV ListView , The problem is, the view returns a list of ALL notes on the system. What I would really prefer is for the list to only return the 'notes' that are associated with a particular CandProfile (model) The notes model is : class CandidateNote(models.Model): candidate = models.ForeignKey(CandProfile, on_delete=models.CASCADE, related_name='candidatenotes_cand') note_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL, related_name=

Getting all objects referenced in a foreign key field

社会主义新天地 提交于 2021-02-10 15:47:01
问题 I have models similar to class Person(Model): name = CharField(max_length=100) class Movie(Model): ... director = ForeignKey(Person) How would I get the set of all Person objects which are set as the director for any Movie object? edit: to clarify, if my Movie 'table' consisted of two entries, one with director A and one with director B, and my Person 'table' consisted of the three entries A, B, and C, I would want to get the set {A, B} 回答1: I figured it out, Person.objects.exclude(director_

Getting all objects referenced in a foreign key field

一笑奈何 提交于 2021-02-10 15:42:46
问题 I have models similar to class Person(Model): name = CharField(max_length=100) class Movie(Model): ... director = ForeignKey(Person) How would I get the set of all Person objects which are set as the director for any Movie object? edit: to clarify, if my Movie 'table' consisted of two entries, one with director A and one with director B, and my Person 'table' consisted of the three entries A, B, and C, I would want to get the set {A, B} 回答1: I figured it out, Person.objects.exclude(director_

ValueError: Cannot use Queryset for “”: Use a Queryset for “”

余生颓废 提交于 2021-02-10 14:50:21
问题 I'm working on a little project using these models here and I'm trying to figure out a way to get a set of all the posts associated with users the currently authenticated user is following. But I keep getting: Cannot use QuerySet for "profile": Use a QuerySet for "User". class Profile(models.Model): user = models.OneToOneField(User) isInstructor = models.BooleanField(default=False) isTutor = models.BooleanField(default=False) isStudent = models.BooleanField(default=False) isAdmin = models

ValueError: Cannot use Queryset for “”: Use a Queryset for “”

女生的网名这么多〃 提交于 2021-02-10 14:48:57
问题 I'm working on a little project using these models here and I'm trying to figure out a way to get a set of all the posts associated with users the currently authenticated user is following. But I keep getting: Cannot use QuerySet for "profile": Use a QuerySet for "User". class Profile(models.Model): user = models.OneToOneField(User) isInstructor = models.BooleanField(default=False) isTutor = models.BooleanField(default=False) isStudent = models.BooleanField(default=False) isAdmin = models

many-to-many relationship of wagtail page model to itself?

巧了我就是萌 提交于 2021-02-10 14:47:44
问题 So i got a PlantDetailPage model with "companion" field among others (yes plants can be companions), in which I should be able to select other PlantDetailPages. I got the thing to show up, create new plants in inline (yes, a menu in the menu in the menu...), but there's few issues: 1) It just won't select them (no action on clicking "select plantdetailpage") 2) "companions" menu button is now shown on the left (like a snippet that it became?) - which I'd like to avoid. 3) I don't know how to

Django: Display File Name for Uploaded File

爷,独闯天下 提交于 2021-02-10 14:26:49
问题 In my model, I have a defined a FileField which my template displays it as a link. My problem is that the linked file displays the url as the name. What shows on html page is: Uploaded File: ./picture.jpg I've looked on the DjangoDocs regarding file names and a previous S.O. question, but just can't figure it out. How can I: Have it display a different name, not a url. Allow the admin who uploaded the file to give it a name, which would then be viewed on the template. my models.py: class

Django model field name “check” raises SystemCheckError

本小妞迷上赌 提交于 2021-02-10 12:33:12
问题 The Django docs state there are only two restrictions on model field names A field name cannot be a Python reserved word A field name cannot contain more than one underscore in a row However, given the following example, it doesn't look like I can use the field name check as a ForeignKey. class Check(models.Model): name = models.CharField(max_length=100) class MyModel(models.Model): # this works fine #check = models.BooleanField() # this breaks check = models.ForeignKey(Check, on_delete