I am creating an app in django, and I have the next problem:
I get a queryset
using the next command line:
queryset = Persons.objects.all()
Assume the resulting list is the next one: ['x', 'y', 'z']
And I want to remove an element x
of that list, so that the resulting list is: ['y', 'z']
.
I don't want to delete the element x
. So I cant use the command item.delete()
.
If my models are:
class A(models.Model):
att1= models.ForeignKey(B)
att2 = models.CharField(max_length=128)
...
class B(models.Model):
ident = models.CharField(max_length=128)
...
How can I get a queryset of B objects that are related with A and A.att2 value == 'test' ???
i think you need to set related_name:
query like this:
this is my first Answer in stackoverflow hope this will help you
if you don't want to set related_name try: