Re: MultipleChoiceField form bug?

2020-12-22 Thread Benny M
Oh this worked out beautifully! Not sure why it hadn’t occurred to me to call 
super().__init__ before hand. And manipulating self.fields was the farthest 
thing from my mind.


As for using ModelMultipleChoiceField - that’s ultimately what I went with for 
the project, but I couldn’t let go of why I couldn’t figure this out. Lol
This is going to be handy in the future. I feel like I have leveled up!

Thanks a ton, Carles!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CH2PR14MB391328ADA5F398BF81643C36C0DE0%40CH2PR14MB3913.namprd14.prod.outlook.com.


Re: MultipleChoiceField form bug?

2020-12-22 Thread Carles Pina i Estany


Hi,

On Dec/22/2020, Benny M wrote:
> That’s correct. I am using a class variable since there doesn’t seem
> to be a DRY - or at least not messy - way of manipulating this from
> __init__.

It's easy to make this mistake. I was bitten by something similar in a
class based view generating a queryset...

> That said, your explanation makes sense and does answer the “why” of
> this. If there’s a way of defining forms inside __init__ I haven’t
> found it… which is not to say that it doesn’t exist.

Yes, you can

> Here’s an example of what I’m referring to: (Pardon my poorly labeled
> model/form names)
> 
> ```
> class M2MForm(forms.ModelForm):
> “”” Populate/update M2MModel name and m2m references ””"
> REF_OPTIONS = ((r.id, r.name) for r in RefModel.objects.all())
> 
> ref_models = forms.MultipleChoiceField(
> widget=forms.SelectMultiple,
> choices=REF_OPTIONS,
> required=False
> )
> 
> class Meta:
> model = M2MModel
> fields = ['name']
> ```


Try something like:

```
class M2MForm(forms.ModelForm):
def __init__(*args, **kwargs):
super().__init__(*args, **kwargs)

# At this point self.fields['name'] already exist...
# ...if you overwriteself.fields['name'] careful
# because you need to save it in save()
#
# self.fields gets created by the __init__() method of
# the parent class (actually grandparent I think :-) )

""" Populate/update M2MModel name and m2m references """
REF_OPTIONS = ((r.id, r.name) for r in RefModel.objects.all())


# this would add the field 'ref_models' in the form, but save()
# will not save. You can overwrite save and save it yourself
self.fields['ref_models'] = forms.MultipleChoiceField(
widget=forms.SelectMultiple,
choices=REF_OPTIONS,
required=False
)

class Meta:
 model = M2MModel
 fields = ['name']
```

I would look at not using forms.MultipleChoiceField and use
forms.ModelMultipleChoiceField(): then you should be able to pass
queryset (first argument for the ModelMultipleChoiceField) and avoid the
REF_OPTIONS=... line

Let me know what you find :-)

Cheers,

> 
> > On Dec 22, 2020, at 9:31 AM, Carles Pina i Estany  wrote:
> > 
> > 
> > 
> > Hi,
> > 
> > On Dec/22/2020, Benny M wrote:
> > 
> >> I’ve ran into some unexpected behavior while testing a ModelForm with
> >> a MultipleChoiceField and am trying to determine if this is a bug, or
> >> if maybe I’m doing something out of the ordinary.
> > 
> > I think that I might guess what it is. If I could see the code it might
> > be easier.
> > 
> > Are you doing something like:
> > 
> > class SomeForm(forms.ModelForm):
> >some_field_options = a_dynamic_expression_that_queries_the_DB
> > 
> >def __init__(*args, **kwargs):
> >your code
> > 
> > So using a class variable instead of an instance variable?
> > 
> > Class variables are initialised on "startup" (I'm simplifying) and only
> > once (and might be used via __new__ on ModelFormMetaclass probably, read
> > and validated).
> > 
> > Either way, if it's not what I've guessed and you paste some code it
> > might help me / someone else to understand it better.
> > 
> > I had once a bug because of using datetime.now() in a class variable
> > when I wanted it the "now" that the view was used not the "now" when the
> > application was started up.
> > 
> > -- 
> > Carles Pina i Estany
> > https://carles.pina.cat
> > 
> > -- 
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to django-users+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/django-users/20201222153133.GA31856%40pina.cat.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CH2PR14MB39136CDA719529325B91F0E3C0DF0%40CH2PR14MB3913.namprd14.prod.outlook.com.
-- 
Carles Pina i Estany
https://carles.pina.cat

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20201223000345.GA24427%40pina.cat.


Re: Django/python free Training

2020-12-22 Thread kerolos emad
very nice to hear that
interested

On Fri, Dec 18, 2020, 4:26 PM Python Class  wrote:

> Hi guys,
>
> I am manucho from Kenya and am good developer with django and python and i
> want to teach people what i know .I want to start a youtube channel for
> Django and python based tutorials ..If intrested you can message me here on
> concepts and projects you want covered and i will start immediately.
>
> Regards,
> Manucho.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5c715780-23c4-4d31-9219-a1e7b92c14f1n%40googlegroups.com
> 
> .
>

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


Re: Ongoing project

2020-12-22 Thread Abdulfarid Olakunle
I am interested, message me on Whatsapp +2348146485170

On Tue, Dec 22, 2020, 15:01 Oyedele Yusuff  wrote:

> I'm interested too
>
> On Thu, 17 Dec 2020 12:42 pm Peter Kirieny, 
> wrote:
>
>> Hello team
>> I have a project in django
>> (developing an ecommerce website with some innovations)
>>
>> Using pycharm and python, am looking for a partner here
>>
>> Am a Kenyan, in Nairobi
>>
>> If interested please inbox for more information
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAL8t8eovVqpPJGfTAE9Q_%3DuPdazu3xxF-79CQxmcf7MNNAL6YA%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAmMZ-kdNuir-hrGFQCb%2BLxHteek0WSWZqQ%3DsmRjcL3Re6urKg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BccuR0Fcm8WiLR0K0SX5SO95V%2B-gAMe6hsauY_Wa5HtecTdng%40mail.gmail.com.


Re: MultipleChoiceField form bug?

2020-12-22 Thread Benny M
That’s correct. I am using a class variable since there doesn’t seem to be a 
DRY - or at least not messy - way of manipulating this from __init__.

That said, your explanation makes sense and does answer the “why” of this. If 
there’s a way of defining forms inside __init__ I haven’t found it… which is 
not to say that it doesn’t exist.

Here’s an example of what I’m referring to:
(Pardon my poorly labeled model/form names)

```
class M2MForm(forms.ModelForm):
“”” Populate/update M2MModel name and m2m references ””"
REF_OPTIONS = ((r.id, r.name) for r in RefModel.objects.all())

ref_models = forms.MultipleChoiceField(
widget=forms.SelectMultiple,
choices=REF_OPTIONS,
required=False
)

class Meta:
model = M2MModel
fields = ['name']
```

> On Dec 22, 2020, at 9:31 AM, Carles Pina i Estany  wrote:
> 
> 
> 
> Hi,
> 
> On Dec/22/2020, Benny M wrote:
> 
>> I’ve ran into some unexpected behavior while testing a ModelForm with
>> a MultipleChoiceField and am trying to determine if this is a bug, or
>> if maybe I’m doing something out of the ordinary.
> 
> I think that I might guess what it is. If I could see the code it might
> be easier.
> 
> Are you doing something like:
> 
> class SomeForm(forms.ModelForm):
>some_field_options = a_dynamic_expression_that_queries_the_DB
> 
>def __init__(*args, **kwargs):
>your code
> 
> So using a class variable instead of an instance variable?
> 
> Class variables are initialised on "startup" (I'm simplifying) and only
> once (and might be used via __new__ on ModelFormMetaclass probably, read
> and validated).
> 
> Either way, if it's not what I've guessed and you paste some code it
> might help me / someone else to understand it better.
> 
> I had once a bug because of using datetime.now() in a class variable
> when I wanted it the "now" that the view was used not the "now" when the
> application was started up.
> 
> -- 
> Carles Pina i Estany
> https://carles.pina.cat
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/20201222153133.GA31856%40pina.cat.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CH2PR14MB39136CDA719529325B91F0E3C0DF0%40CH2PR14MB3913.namprd14.prod.outlook.com.


Re: MultipleChoiceField form bug?

2020-12-22 Thread Carles Pina i Estany



Hi,

On Dec/22/2020, Benny M wrote:

> I’ve ran into some unexpected behavior while testing a ModelForm with
> a MultipleChoiceField and am trying to determine if this is a bug, or
> if maybe I’m doing something out of the ordinary.

I think that I might guess what it is. If I could see the code it might
be easier.

Are you doing something like:

class SomeForm(forms.ModelForm):
some_field_options = a_dynamic_expression_that_queries_the_DB

def __init__(*args, **kwargs):
your code

So using a class variable instead of an instance variable?

Class variables are initialised on "startup" (I'm simplifying) and only
once (and might be used via __new__ on ModelFormMetaclass probably, read
and validated).

Either way, if it's not what I've guessed and you paste some code it
might help me / someone else to understand it better.

I had once a bug because of using datetime.now() in a class variable
when I wanted it the "now" that the view was used not the "now" when the
application was started up.

-- 
Carles Pina i Estany
https://carles.pina.cat

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20201222153133.GA31856%40pina.cat.


Re: Django/python free Training

2020-12-22 Thread Jonathan Mator
I am interested

On Mon, Dec 21, 2020, 12:40 PM David Zea  wrote:

> Hi.
>
> I'm  Interested!
>
>
> El vie, 18 dic 2020 a las 9:26, Python Class ()
> escribió:
>
>> Hi guys,
>>
>> I am manucho from Kenya and am good developer with django and python and
>> i want to teach people what i know .I want to start a youtube channel for
>> Django and python based tutorials ..If intrested you can message me here on
>> concepts and projects you want covered and i will start immediately.
>>
>> Regards,
>> Manucho.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/5c715780-23c4-4d31-9219-a1e7b92c14f1n%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALsZvTtRGrEfqiOgReB4kmw_EtCteKKx-QYxXq0shqsrL7q5fw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B1BtCQmrcKEUin8M3N1g-Jmw67J2%2BWxMqXBo55GTPWObs5P8w%40mail.gmail.com.


Re: Django/python free Training

2020-12-22 Thread Claive NKOKOLO MALANDA
Hi i'm interested!

Le vendredi 18 décembre 2020 à 15:27:14 UTC+1, rampage...@gmail.com a 
écrit :

> Hi guys,
>
> I am manucho from Kenya and am good developer with django and python and i 
> want to teach people what i know .I want to start a youtube channel for 
> Django and python based tutorials ..If intrested you can message me here on 
> concepts and projects you want covered and i will start immediately.
>
> Regards,
> Manucho.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/380bea17-b86c-4a13-ab65-35103be9beb8n%40googlegroups.com.


Re: Ongoing project

2020-12-22 Thread Oyedele Yusuff
I'm interested too

On Thu, 17 Dec 2020 12:42 pm Peter Kirieny,  wrote:

> Hello team
> I have a project in django
> (developing an ecommerce website with some innovations)
>
> Using pycharm and python, am looking for a partner here
>
> Am a Kenyan, in Nairobi
>
> If interested please inbox for more information
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAL8t8eovVqpPJGfTAE9Q_%3DuPdazu3xxF-79CQxmcf7MNNAL6YA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAmMZ-kdNuir-hrGFQCb%2BLxHteek0WSWZqQ%3DsmRjcL3Re6urKg%40mail.gmail.com.


MultipleChoiceField form bug?

2020-12-22 Thread Benny M
Hi all,

I’ve ran into some unexpected behavior while testing a ModelForm with a 
MultipleChoiceField and am trying to determine if this is a bug, or if maybe 
I’m doing something out of the ordinary.

In the form, I’m generating the MultipleChoiceField choices on the fly. e.g. 
`OPTIONS = ((m.id, m.name) for m in Model.objects.all())` then 
assigning `OPTIONS` to the `choices` attribute in the field declaration.

When running the test the form generates the choices from the non-test db, 
which results in a failure, as I’m creating the model instance for POST in the 
test. So because of this behavior, the instance created in the test isn’t part 
of the form choices.

It seems like:
- ./manage.py test
- Generate form choices
- Instantiate Test
- Test creates expected choice(s) and calls view with POST data
- form.is_valid() fails due to generated test instance not being in choices

It seems odd to me that the form is (or at least parts of it are) being built 
before any direct reference to it is instantiated. But this may be 
normal/expected behavior. I’ve seen the same behavior in 1.11 and 3.1.4, so 
it’s most likely that my method for dynamically generating choices isn’t kosher.

Anyway, if this sounds like a possible bug let me know and I’ll submit an issue 
with steps to reproduce, or provide more information here on request.


Thanks,
Benny

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CH2PR14MB391319A069301FDB1FE1DE4FC0DF0%40CH2PR14MB3913.namprd14.prod.outlook.com.


Re: Apple M1 Silicon + Django = weird results

2020-12-22 Thread Benjamin Schollnick
Just an update.

Working my way through the problem, it appears that either the data is being 
written truncated to the database, or Pillow is generating a truncated image 
preview (which is being stored to the database).

The later is more likely, since I am seeing no other data corruption errors.

Rewriting the thumbnail delivery code, seemed to reduce the amount of 
downloading issues, but they are still not Non-Zero…  

But I may just have to live with this, since there are too many moving parts to 
be able to point a finger at any one bit of code.  (It could be rosetta 2 
overly optimizing the code in some way…  etc.)

Plus, It might be time for me to just simply start rewriting the code from the 
ground up again, to better optimize and clean it up.  

- Benjamin



> On Dec 21, 2020, at 10:52 PM, Benjamin Schollnick 
>  wrote:
> 
> 
>> Have you tried the download with various browsers? I wonder if Safari or 
>> Chrome released at the same time as the M1 chips is causing different Range 
>> header behavior than that code is designed to handle. So it might not be the 
>> M1 chip, but just an unrelated change in browser software that got pushed 
>> out at the same time. Speculating here.
> 
> The only issue that I see, is that I started to use RangedFileResponse to 
> allow the viewing of MP4, and other media files in the browser…  (
> 
> So I know it works at least in that regard.  
> 
> But for debugging purposes, I’ll switch it around…
> 
>   - Benjamin
> 
> 
>> 
>> On Mon, Dec 21, 2020 at 3:19 PM Benjamin Schollnick 
>> mailto:bscholln...@schollnick.net>> wrote:
>> Folks,
>> 
>> I’m using django for an online gallery application, and I’ve seen some weird 
>> results since switching over to the M1 Mac Mini.
>> (Please note, I am running it under Rosetta / Intel Translation, since 
>> pillow doesn’t seem to build under M1 native).
>> 
>> So this could be a quirk of Rosetta, Django, or some combination of these.
>> 
>> I don’t think so, but it could be.
>> 
>> So What is happening?  
>> 
>> I never saw this under my 2013 intel iMac, but now under M1 (even under 
>> Rosetta 2 / Intel translation) I am receiving a damaged / altered download 
>> file roughly 6 out of 8 or 9 times (~25-33% successful).  
>> 
>> Just retrying the download will eventually be successful.  
>> 
>> This isn’t Pillow related, since the file is just being downloaded directly 
>> (no thumbnails or alterations to the file is occurring).
>> 
>> Does anyone have a suggestion on what to do at this time?  I’m uncertain on 
>> where to start to dig.  Although removing ranged_response, might be a 
>> starting point…
>> 
>> URLs:
>> path("download/", frontend.views.new_download, 
>> name="downloads"),
>> path('thumbnails/', frontend.views.thumbnails, 
>> name="raw thumbnails"),
>> 
>> 
>> First, I am using these function for all graphics and/or file(s) being sent:
>> 
>> def new_download(request, d_uuid=None):
>> page = request.GET.get('page', None)
>> if page is None:
>> download = index_data.objects.filter(uuid=d_uuid,
>>  ignore=False,
>>  delete_pending=False)[0]
>> else:
>> print ("Attempting to find page %s in archive" % page)
>> print("\tDownloading - %s, %s" % (download.fqpndirectory.lower(),
>>   download.name ))
>> return respond_as_inline(request,
>>  "%s%s%s" % (
>>  configdata["locations"]["albums_path"],
>>  os.sep,
>>  download.fqpndirectory),
>>  download.name )
>> 
>> 
>> def respond_as_inline(request, file_path, original_filename, ranged=False):
>> # https://stackoverflow.com/questions/36392510/django-download-a-file 
>> 
>> # 
>> https://stackoverflow.com/questions/27712778/video-plays-in-other-browsers-but-not-safari
>>  
>> 
>> # 
>> https://stackoverflow.com/questions/720419/how-can-i-find-out-whether-a-server-supports-the-range-header
>>  
>> 
>> filename = os.path.join(file_path, original_filename)
>> if os.path.exists(filename):
>> mtype, encoding = mimetypes.guess_type(original_filename)
>> if mtype is None:
>> mtype = 'application/octet-stream'
>> response = RangedFileResponse(request, file=open(filename, 'rb'), 
>> as_attachment=False, filename=os.path.basename(filename))
>> response["Content-Type"] = mtype
>> return response
>> raise Http404
>> 
>> 
>> 
>> -- 
>> You received this