Re: ModelAdmin missing a couple of key features, or am I doing this wrong?

2016-09-17 Thread James Schneider
On Sep 16, 2016 1:46 AM, "Andrea D'Amore"  wrote:
>
> On 16 September 2016 at 00:53,   wrote:
> > I have a ModelAdmin subclass (code at: )
>
> Gives a 404:
>
> The requested URL /0LAt was not found on this server.
>
>
> I'm missing the rationale of using an external paste service while
> you're already using a text-based medium, the mailing list, that's
> able to accomodate what's (hopefully) a small code excerpt, in worst
> case scenario I think it'll accept an attachment as well.
>
> This also has the added bonus of getting archived and never result in
> broken links and missing content, like it's likely to happen at some
> point with external services.
>

(OT Disclaimer...not directed at this OP.)

I would [mostly] disagree.

Rationale: A majority of my responses (including this one) are written on
my phone while I'm bored and out and about, or at night during my pre-bed
email check. While the GMail app is great, I've never seen it employ any
sort of code highlighting or sane code wrapping or indentation, beyond
copying directly out of an SO post or other snippet service. Probably
because the GMail app is an email client, not an IDE. There is also no real
way to preview the effects of spacing and line wrapping on multiple
devices, screen sizes, HTML vs. plain text, Unicode handling, etc.
Basically, there's a bunch of ways a direct paste from an IDE can go
sideways in an email, with an increasing likelihood for large code chunks.
Difficult-to-read code directly in an email will deter responses. It does
for me, anyway.

For small code snippets, absolutely, paste them directly in and just make
sure your indentation is at least consistent. If you have more than a dozen
or so SLOC, though, try and reduce the provided code to the stuff that's
necessary (which will often force an OP to really evaluate what their code
is doing and aid in troubleshooting), or make use of an external service
such as dpaste.de.

Mobile devices cannot always open external files, especially those with
less common extensions such as .py. It also fills up your mailbox,
needlessly. I rarely, if ever, open the attachments sent out to this list.
Trying to keep track of the original question compared with the code in a
separate application screen on a mobile device is nearly impossible.

A majority of the code in this list doesn't need to live forever once the
OP has a proper answer. A response with a summation of the correct solution
is almost always the key piece needed when searching through the archives
or Googling, at least in my experience with this list and other forums.

With that being said, sometimes the OP may not know the exact pieces that
are needed for inspection, or there are multiple files involved, so an
attachment may be necessary. Code snippet services also lack in this area.

IMHO, you hijacked this thread to insert your preference for posts, without
offering a single bit of advice to the OP, which reflects poorly on you. I
would offer advice to the OP, but I have none because I have little
experience using the built-in admin.

I would recommend that you offer suggestions for posting guidelines to the
moderators of this list and/or the Django devs. Help move this community
forward rather than criticising those requesting assistance, especially on
a point of personal preference.

Just my personal opinion; if I'm out of line, someone please let me know.

-James

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciW3FQNo1g%2B%2BBxw3zNWEPiOGfQ6EnixO-Th0geTDPrk1qg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelAdmin missing a couple of key features, or am I doing this wrong?

2016-09-16 Thread thauk
Apologies, I updated it.


class MyModelAdmin(ModelAdmin):
model = MyModel
form = MyForm
 
def get_form(self, request, obj=None, **kwargs):
form_class = super(MyModelAdmin, self).get_form(request, obj=obj, 
**kwargs)
 
some_parameter_for_one_thing = 
self.get_some_parameter_for_one_thing()
 
from django.forms.models import ModelFormMetaclass
class FormMetaclass(ModelFormMetaclass):
def __new__(mcs, name, bases, attrs):
attrs["some_parameter_for_one_thing"] = 
some_parameter_for_one_thing
return super(FormMetaclass, mcs).__new__(mcs, name, bases, 
attrs)
 
another_parameter_for_another_thing= 
obj.another_parameter_for_another_thing
 
import six
class FormWrapper(six.with_metaclass(FormMetaclass, form_class)):
def __init__(self, *args, **kwargs):
data = {"another_parameter_for_another_thing": 
six.text_type(another_parameter_for_another_thing)}
super(FormWrapper, self).__init__(data, *args, **kwargs)
 
return FormWrapper

On Friday, September 16, 2016 at 1:46:32 AM UTC-7, Andrea D'Amore wrote:
>
> On 16 September 2016 at 00:53,   
> wrote: 
> > I have a ModelAdmin subclass (code at: ) 
>
> Gives a 404: 
>
> The requested URL /0LAt was not found on this server. 
>
>
> I'm missing the rationale of using an external paste service while 
> you're already using a text-based medium, the mailing list, that's 
> able to accomodate what's (hopefully) a small code excerpt, in worst 
> case scenario I think it'll accept an attachment as well. 
>
> This also has the added bonus of getting archived and never result in 
> broken links and missing content, like it's likely to happen at some 
> point with external services. 
>
>
> -- 
> Andrea 
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9481df50-3280-4b9d-87c2-080e632a4cda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelAdmin missing a couple of key features, or am I doing this wrong?

2016-09-16 Thread Andrea D'Amore
On 16 September 2016 at 00:53,   wrote:
> I have a ModelAdmin subclass (code at: )

Gives a 404:

The requested URL /0LAt was not found on this server.


I'm missing the rationale of using an external paste service while
you're already using a text-based medium, the mailing list, that's
able to accomodate what's (hopefully) a small code excerpt, in worst
case scenario I think it'll accept an attachment as well.

This also has the added bonus of getting archived and never result in
broken links and missing content, like it's likely to happen at some
point with external services.


-- 
Andrea

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMonFrQ%2B2JYMPEaOXw-FM2Oj--BxjNNrqsO6isEDgFGf%3DHnd0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelAdmin missing a couple of key features, or am I doing this wrong?

2016-09-15 Thread thauk
I just realized that get_form is already passed the model instance as obj, 
so that fixes getting he model instance (for this method at least -- 
hopefully I don't need to override another method that doesn't get obj). 
Still need a better way to customize how a form instance is initialized, 
though...

On Thursday, September 15, 2016 at 6:00:02 PM UTC-7, th...@copperleaf.com 
wrote:
>
> Hi Tim, thanks for the reply :)
>
> It's not that I want to store the model instance on self.instance, it's 
> just the solution I was able to come up with, given the problem "I need to 
> get to the model instance for this HTTP request". If there's a better way 
> to do it, I'm all ears!
>
> T
>
> On Thursday, September 15, 2016 at 5:34:50 PM UTC-7, Tim Graham wrote:
>>
>> I think these ideas have been floated before. If you look through the 
>> Trac tickets you might find something related. However, your subclass where 
>> you store "self.instance" on ModelAdmin is a no no due to thread safety. 
>> See 
>> http://stackoverflow.com/questions/3388111/modeladmin-thread-safety-caching-issues
>>  
>> for an explanation.
>>
>> On Thursday, September 15, 2016 at 6:53:15 PM UTC-4, th...@copperleaf.com 
>> wrote:
>>>
>>> I have a ModelAdmin subclass (code at: ) and I 
>>> need to do a couple of things, but the functionality seems to be missing:
>>>
>>> 1. I need to access the model instance to perform some initialization, 
>>> but there's no instance member set. There are a few questions on Stack 
>>> Overflow on this topic, so I know I'm not alone.
>>>
>>> 2. I need to initialize my form with a parameter derived from the model 
>>> instance. If this were a View, I could just override get_form_kwargs and be 
>>> done with it, but ModelAdmin doesn't have it.
>>>
>>> Is there a reason why those two features are missing from ModelAdmin? 
>>> Maybe they could be added (and I could open a PR)? Or is there a better way 
>>> to do what I need to do?
>>>
>>>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2a245d08-91b3-4a16-a3b2-4e172d2cbcb4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelAdmin missing a couple of key features, or am I doing this wrong?

2016-09-15 Thread thauk
I'm having trouble finding any related tickets other than this one, which 
is 8 years old:

https://code.djangoproject.com/ticket/10305

On Thursday, September 15, 2016 at 5:34:50 PM UTC-7, Tim Graham wrote:
>
> I think these ideas have been floated before. If you look through the Trac 
> tickets you might find something related. However, your subclass where you 
> store "self.instance" on ModelAdmin is a no no due to thread safety. See 
> http://stackoverflow.com/questions/3388111/modeladmin-thread-safety-caching-issues
>  
> for an explanation.
>
> On Thursday, September 15, 2016 at 6:53:15 PM UTC-4, th...@copperleaf.com 
> wrote:
>>
>> I have a ModelAdmin subclass (code at: ) and I 
>> need to do a couple of things, but the functionality seems to be missing:
>>
>> 1. I need to access the model instance to perform some initialization, 
>> but there's no instance member set. There are a few questions on Stack 
>> Overflow on this topic, so I know I'm not alone.
>>
>> 2. I need to initialize my form with a parameter derived from the model 
>> instance. If this were a View, I could just override get_form_kwargs and be 
>> done with it, but ModelAdmin doesn't have it.
>>
>> Is there a reason why those two features are missing from ModelAdmin? 
>> Maybe they could be added (and I could open a PR)? Or is there a better way 
>> to do what I need to do?
>>
>>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/43ace9be-231e-4ae9-bc04-b04b201c4962%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelAdmin missing a couple of key features, or am I doing this wrong?

2016-09-15 Thread thauk
Hi Tim, thanks for the reply :)

It's not that I want to store the model instance on self.instance, it's 
just the solution I was able to come up with, given the problem "I need to 
get to the model instance for this HTTP request". If there's a better way 
to do it, I'm all ears!

T

On Thursday, September 15, 2016 at 5:34:50 PM UTC-7, Tim Graham wrote:
>
> I think these ideas have been floated before. If you look through the Trac 
> tickets you might find something related. However, your subclass where you 
> store "self.instance" on ModelAdmin is a no no due to thread safety. See 
> http://stackoverflow.com/questions/3388111/modeladmin-thread-safety-caching-issues
>  
> for an explanation.
>
> On Thursday, September 15, 2016 at 6:53:15 PM UTC-4, th...@copperleaf.com 
> wrote:
>>
>> I have a ModelAdmin subclass (code at: ) and I 
>> need to do a couple of things, but the functionality seems to be missing:
>>
>> 1. I need to access the model instance to perform some initialization, 
>> but there's no instance member set. There are a few questions on Stack 
>> Overflow on this topic, so I know I'm not alone.
>>
>> 2. I need to initialize my form with a parameter derived from the model 
>> instance. If this were a View, I could just override get_form_kwargs and be 
>> done with it, but ModelAdmin doesn't have it.
>>
>> Is there a reason why those two features are missing from ModelAdmin? 
>> Maybe they could be added (and I could open a PR)? Or is there a better way 
>> to do what I need to do?
>>
>>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/39bbf43e-3a6c-47a4-ab4d-46e5c49cf32b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelAdmin missing a couple of key features, or am I doing this wrong?

2016-09-15 Thread Tim Graham
I think these ideas have been floated before. If you look through the Trac 
tickets you might find something related. However, your subclass where you 
store "self.instance" on ModelAdmin is a no no due to thread safety. See 
http://stackoverflow.com/questions/3388111/modeladmin-thread-safety-caching-issues
 
for an explanation.

On Thursday, September 15, 2016 at 6:53:15 PM UTC-4, th...@copperleaf.com 
wrote:
>
> I have a ModelAdmin subclass (code at: ) and I 
> need to do a couple of things, but the functionality seems to be missing:
>
> 1. I need to access the model instance to perform some initialization, but 
> there's no instance member set. There are a few questions on Stack Overflow 
> on this topic, so I know I'm not alone.
>
> 2. I need to initialize my form with a parameter derived from the model 
> instance. If this were a View, I could just override get_form_kwargs and be 
> done with it, but ModelAdmin doesn't have it.
>
> Is there a reason why those two features are missing from ModelAdmin? 
> Maybe they could be added (and I could open a PR)? Or is there a better way 
> to do what I need to do?
>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8555185b-0cec-4fc7-96e5-0cdb2ff7d8c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ModelAdmin missing a couple of key features, or am I doing this wrong?

2016-09-15 Thread thauk
I have a ModelAdmin subclass (code at: ) and I need 
to do a couple of things, but the functionality seems to be missing:

1. I need to access the model instance to perform some initialization, but 
there's no instance member set. There are a few questions on Stack Overflow 
on this topic, so I know I'm not alone.

2. I need to initialize my form with a parameter derived from the model 
instance. If this were a View, I could just override get_form_kwargs and be 
done with it, but ModelAdmin doesn't have it.

Is there a reason why those two features are missing from ModelAdmin? Maybe 
they could be added (and I could open a PR)? Or is there a better way to do 
what I need to do?

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/26d907aa-6427-4cac-9653-0f656a90caf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.