I have been struggling all morning trying to figure out how to compare two different querysets. I have two manytomanyfields in my model, and I'm trying to figure out if they are identical.
I research this by viewing this particular issue: How do I test Django QuerySets are equal?
I am using class based views...and I have a model with two manytomanyfields...
My model...
class Author(models.Model):
title = models.ManyToManyField(User,blank=True,related_name='title')
title1 = models.ManyToManyField(User,blank=True,related_name='title1)
My View...
class AuthorDetailView(DetailView):
model = Author
def get_context_data(self, **kwargs):
context = super(AuthorDetailView, self).get_context_data(**kwargs)
title = list(Author.objects.filter(title))
title1 = list(Author.objects.filter(title1))
test_instance = Author.objects.all()
proxy4 = self.assertQuerySetEqual(Author.objects.all(), map(repr, [test_instance]))
I am trying to compare fields title and title1. However when try to run the code above I continually get a 'View' object has no attribute 'assertQuerysetEqual'. I can't even get this function to work. I running Django 1.11 and Postgresql. Perhaps this function doesn't work with Postgresql? Any help to get me on the right track is appreciated. Been playing with this and researching all morning with no luck. Thanks in advance.
Update...I have also been playing with various versions of trying to compare title_set.all and title1_set.all in the views....this is working intermittently...but the two are always returning that they are equal.