Re: Desired behaviour when passing a non boolean to filter(*__isnull)

2019-10-03 Thread 'Alexandr Aktsipetrov' via Django developers (Contributions to Django itself)

On Monday, September 30, 2019 at 5:47:12 PM UTC+3, André Ericson wrote:
>
> Hello,
>
> I came across the discovery (due to a bug on our code) that it's possible 
> to pass a non-boolean to the __isnull filter. What would be the desired 
> behavior here?
> Should we raise an exception or should Django use the truthy value?
>

As an anecdote, I've also got bitten by this possibility. 
An attempt to write WHERE (field IS NULL) = boolean_field as 
.filter(field__isnull=F('boolean_field')) didn't go as I expected. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/a0558991-09d1-4b74-9b19-05a1e07916ba%40googlegroups.com.


Re: id the field is required - error in Django formset

2019-10-03 Thread Adam Johnson
Hi!

I think you've found the wrong mailing list for this post. This mailing
list is for the development of Django itself, not for support using Django.
This means the discussions of bugs and features in Django itself, rather
than in your code using it. People on this list are unlikely to answer your
support query with their limited time and energy. Read more on the mailing
lists at https://www.djangoproject.com/community/

For support, please use the NEW Django forum at
https://forum.djangoproject.com , django-users mailing list, or IRC #django
on Freenode, or a site like Stack Overflow. There are people out there
willing to help on those channels, but they might not respond if you don't
ask your question well. Stack Overflow's question guide can help you frame
it well: https://stackoverflow.com/help/how-to-ask .

Also if you haven't read it, please take a look at Django's Code of
Conduct: https://www.djangoproject.com/conduct/ . These are our "ground
rules" for working well as a community, and will help you get the most out
of Django and our fantastic community.

Thanks for your understanding,

Adam

On Thu, 3 Oct 2019 at 12:23,  wrote:

> I am using django 2.2. My models are
>
> class Group(models.Model):
> group_name = models.CharField(max_length=100)
> def __str__(self):
> return self.group_nameclass Category(models.Model):
> category_name = models.CharField(max_length=50)
> def __str__(self):
> return self.category_nameclass Profile(models.Model):
> user = models.OneToOneField(User, on_delete=models.CASCADE)
> board = models.CharField(choices=board_options,max_length=1,null=True)
> group = models.ForeignKey(Group,on_delete=models.CASCADE,null=True)
> class Subject(models.Model):
> subject_name = models.CharField(max_length=50)
> subject_category = models.ForeignKey(Category, on_delete=models.CASCADE)
> subject_photo = models.ImageField(null=True,blank=True)
> def __str__(self):
> return self.subject_name
> class Subject_Assignment(models.Model):
> board = models.CharField(choices=board_options,max_length=1,null=True)
> group = models.ForeignKey(Group,on_delete=models.CASCADE,null=True)
> Subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
> class Mark_Survey(models.Model):
> survey_name = models.CharField(max_length=50)
> opens_at =  models.DateField()
> ends_at = models.DateField()
> class Survey_Mark(models.Model):
> mark_survey = models.ForeignKey(Mark_Survey,on_delete=models.CASCADE)
> user = models.ForeignKey(User, on_delete=models.CASCADE)
> Subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
> marks = models.IntegerField()
>
> Here am creating a formset for Survey_Mark and my form should get marks of
> all Subject. By using Subject_Assignment i can get all the subjects of the
> particular user.The following view works for the get method but throws
> error in post method.
>
> def postsurvey(request,pk):
> #post = get_object_or_404(Mark_Survey, pk=pk)
> SurveyFormSet = modelformset_factory(Survey_Mark, 
> fields=('marks','Subject'),extra=0)
> if request.method == "POST":
> formset = SurveyFormSet(request.POST,request.FILES)
> print(formset.data)
> print(formset.errors)
>
> if formset.is_valid():
> post = formset.save(commit=False)
> post.mark_survey=pk
> post.user=request.user
> post.save()
> html = "Success" % now
> return HttpResponse(html)
> else:
> print("failure")
> html = "failure "
> return HttpResponse(html)
>
> else:
> user=request.user
> profile = get_object_or_404(Profile,user_id=user.id)
> formset = 
> SurveyFormSet(queryset=Subject_Assignment.objects.filter(Q(board=profile.board)
>  & Q(group=profile.group)))
> return render(request, 'subject_assignment_detail.html', {'formset': 
> formset})
>
> Am getting id the field is required error. if i used {{ hidden }} in
> template then am getting *Select a valid choice. That choice is not one
> of the available choices* error in post method.I want to get marks of all
> the subject in single form and save it in the corresponding table
>
> --
> with regards,
> B.Madusudhanan,
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CAMYHm%2Bd_cd-gaAgcwKjfVq%2BEuNreS0h1sHhcNustj5e2ZbuEww%40mail.gmail.com
> 
> .
>


-- 
Adam

-- 
You received this mess

Re: Desired behaviour when passing a non boolean to filter(*__isnull)

2019-10-03 Thread André Ericson
The problem I found is that a join doesn't get promoted to an outer. I
already started fixing it, will make a PR soon.
Was the same problem you had?

On Thu, Oct 3, 2019 at 1:32 PM 'Alexandr Aktsipetrov' via Django developers
(Contributions to Django itself)  wrote:

>
> On Monday, September 30, 2019 at 5:47:12 PM UTC+3, André Ericson wrote:
>>
>> Hello,
>>
>> I came across the discovery (due to a bug on our code) that it's possible
>> to pass a non-boolean to the __isnull filter. What would be the desired
>> behavior here?
>> Should we raise an exception or should Django use the truthy value?
>>
>
> As an anecdote, I've also got bitten by this possibility.
> An attempt to write WHERE (field IS NULL) = boolean_field as
> .filter(field__isnull=F('boolean_field')) didn't go as I expected.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-developers/AhY2b3rxkfA/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/a0558991-09d1-4b74-9b19-05a1e07916ba%40googlegroups.com
> 
> .
>


-- 
André Ericson

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAC5qeUYNMdaRsrgLeGMBrwEgAE_sy0hacNR2c6emCc%3DYfJgfpQ%40mail.gmail.com.