Subparsers for management commands

2023-01-10 Thread Mark Gregson
I was just looking at custom management commands (Django 3.2) and noted 
that the error handling for a subparser didn't match the Django behaviour 
without some extra, undocumented work. 

If my Command subclass implements the following:

def add_arguments(self, parser):
subparsers = parser.add_subparsers()
sub = subparsers.add_parser("thing")

errors raised by the subparser, eg, for missing arguments, result in the 
command exiting with a stack trace.  Normal behaviour in Django when a 
command is called from the command line is a nice error message and I 
expect subparsers to act the same way.

The error handling behaviour depends on the parser.called_from_command_line 
attribute which must be set manually for subparsers to achieve the same, 
eg: 

sub = subparsers.add_parser("thing", called_from_command_line=
parser.called_from_command_line) 

I'd propose adding a little documentation about this argument with an 
example so that the next me doesn't need to hunt through the code to 
understand what's happening.

Another option would be to add a convenience method that would ensure  
called_from_command_line is set correctly, eg, 

class CommandParser:
def add_subparser(self, subparsers, name, **kwargs):
kwargs.setdefault(
"called_from_command_line", 
self.called_from_command_line
)
return subparsers.add_parser(name, **kwargs)

which would save repetition but would still require command authors have 
some special Django knowledge so I'd question whether it's worthwhile.

I'm happy to contribute if advised on the preferred option.

Cheers
Mark

-- 
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/06855745-cff7-4474-8538-2589d0a0a650n%40googlegroups.com.


Re: ticket 5929

2023-01-10 Thread Barhamou Hama
Hi, I'm glad I contributed to something. I understand your point of view. 
I'm new and looking for an interesting topic to work on in my spare time. 
I don't want to waste my energy on a feature that doesn't get a lot of 
support.
However, if this ticket still exists, there must be a problem somewhere.
Le mardi 10 janvier 2023 à 15:23:35 UTC+1, tob...@caktusgroup.com a écrit :

> Thank you Barhamou for raising the question here and starting the 
> discussion.
>
> I agree with Adrian that this feels like a pretty niche use case.  
> Depending on the needs, other possible implementations might include:
>
> 4. A form field mapping to multiple model fields
> 5. A custom queryset/manager that takes "shorthand filter queries" and 
> expands them to multiple model fields
>
> As for the example in #5929  
> ticket 
> description, that is probably best solved with #2 on Adrian's list, for 
> example the django-netfields  
> project 
> for Postgres.
>
> On Mon, Jan 9, 2023 at 9:59 AM Barhamou Hama  wrote:
>
>> Hence the interest of my question, if in 15 years it has not been solved, 
>> there must be a reason.
>>
>> Le lundi 9 janvier 2023 à 12:57:31 UTC+1, ator...@redhat.com a écrit :
>>
>>> I feel like this is a very niche use case and probably doesn't warrant 
>>> implementing field-to-column one-to-many relationships in Django, I don't 
>>> see why this specific case can't be implemented as:
>>>
>>> 1. A model that implements the data type
>>> 2. A custom field + custom datatype on the database backend
>>> 3. ArrayField [1] if using postgres
>>>
>>> [1] 
>>> https://docs.djangoproject.com/en/4.1/ref/contrib/postgres/fields/#arrayfield
>>> On Monday, January 9, 2023 at 12:16:56 AM UTC+1 cur...@tinbrain.net 
>>> wrote:
>>>
 On Sun, 8 Jan 2023, at 23:29, Barhamou Hama wrote:

 Hi all, I came across this ticket here 
  opened 15 years ago that 
 doesn't seem to have been resolved. I decided to work on it. But in 15 
 years a lot can happen. Is it still relevant? Has there been any progress 
 on this issue?
  


 IIRC there's no current support for this, the closest being 
 GenericForeignKeys, which still require their sub-fields defined 
 separately.

 There has been posts about supporting joint using multi-field keys (
 https://devblog.kogan.com/blog/custom-relationships-in-django) 
 however, that's a rather specific case.

 I think it would be a good thing for progress on this issue to happen.

 You might also want to check the ticket history for any work on 
 multi-value keys.

 --
 Curtis


 -- 
>> 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-develop...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-developers/9e4ee8c9-aa22-4ac1-bd70-1c87427ca955n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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/0fa26341-edf0-4b98-8ca1-042162978953n%40googlegroups.com.


Re: GSOC 2023

2023-01-10 Thread Tim Graham
Hello all, please take a look at 
https://docs.djangoproject.com/en/dev/internals/contributing/new-contributors/ 
to find advice for new contributors.

On Tuesday, January 10, 2023 at 11:26:12 AM UTC-5 arpitasriv...@gmail.com 
wrote:

> Hello Everyone , myself Arpita Srivastava a pre final year computer 
> science student.
> I want to contribute in GSoC 2023 as my skill sets include python , 
> Django. So I have chosen Django as the organization to contribute in.  
> I was hoping If I could get some help from the Django & python community. 
> About how to start.
>

-- 
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/c8d64741-629a-4381-af9e-809c8a7c50bfn%40googlegroups.com.


GSOC 2023

2023-01-10 Thread ArpitA Srivastava
Hello Everyone , myself Arpita Srivastava a pre final year computer science 
student.
I want to contribute in GSoC 2023 as my skill sets include python , Django. 
So I have chosen Django as the organization to contribute in.  
I was hoping If I could get some help from the Django & python community. 
About how to start.

-- 
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/cd6efe4e-53a6-499b-8a67-46b4e7142131n%40googlegroups.com.


Re: ticket 5929

2023-01-10 Thread 'Tobias McNulty' via Django developers (Contributions to Django itself)
Thank you Barhamou for raising the question here and starting the
discussion.

I agree with Adrian that this feels like a pretty niche use case.
Depending on the needs, other possible implementations might include:

4. A form field mapping to multiple model fields
5. A custom queryset/manager that takes "shorthand filter queries" and
expands them to multiple model fields

As for the example in #5929  ticket
description, that is probably best solved with #2 on Adrian's list, for
example the django-netfields
 project
for Postgres.

On Mon, Jan 9, 2023 at 9:59 AM Barhamou Hama  wrote:

> Hence the interest of my question, if in 15 years it has not been solved,
> there must be a reason.
>
> Le lundi 9 janvier 2023 à 12:57:31 UTC+1, ator...@redhat.com a écrit :
>
>> I feel like this is a very niche use case and probably doesn't warrant
>> implementing field-to-column one-to-many relationships in Django, I don't
>> see why this specific case can't be implemented as:
>>
>> 1. A model that implements the data type
>> 2. A custom field + custom datatype on the database backend
>> 3. ArrayField [1] if using postgres
>>
>> [1]
>> https://docs.djangoproject.com/en/4.1/ref/contrib/postgres/fields/#arrayfield
>> On Monday, January 9, 2023 at 12:16:56 AM UTC+1 cur...@tinbrain.net
>> wrote:
>>
>>> On Sun, 8 Jan 2023, at 23:29, Barhamou Hama wrote:
>>>
>>> Hi all, I came across this ticket here
>>>  opened 15 years ago that
>>> doesn't seem to have been resolved. I decided to work on it. But in 15
>>> years a lot can happen. Is it still relevant? Has there been any progress
>>> on this issue?
>>>
>>>
>>>
>>> IIRC there's no current support for this, the closest being
>>> GenericForeignKeys, which still require their sub-fields defined separately.
>>>
>>> There has been posts about supporting joint using multi-field keys (
>>> https://devblog.kogan.com/blog/custom-relationships-in-django) however,
>>> that's a rather specific case.
>>>
>>> I think it would be a good thing for progress on this issue to happen.
>>>
>>> You might also want to check the ticket history for any work on
>>> multi-value keys.
>>>
>>> --
>>> Curtis
>>>
>>>
>>> --
> 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/9e4ee8c9-aa22-4ac1-bd70-1c87427ca955n%40googlegroups.com
> 
> .
>

-- 
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/CAMGFDKRDeF-VqnYg%2BHmTYo-pT1QyG61dUKKqm3Ai_jSKnb984g%40mail.gmail.com.