Re: Non-primary auto-incrementing field with Postgres

2017-06-21 Thread thauk

On Tuesday, June 20, 2017 at 10:40:05 PM UTC-7, Scot Hacker wrote:
>
> One strategy might be to:
>
> 1) Bring in the data under a different column name ('old_id' ?)
> 2) In a single migration, drop the default ID column,  rename old_id to 
> id, and give it primary_key=True
>

I can't change the primary key for this table, unfortunately.

T
 

-- 
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/f72ddf1d-c7f6-4df3-b2c6-62bba2e4a672%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Testing a Django library

2017-03-20 Thread thauk
I am working on a Django library (which will be packaged) and want to set 
up testing for it. Looking at a number of existing Django libraries, here 
seem to be a number of ways to set up testing, and all of them are 
different.

Are there any best practices? Is there a guide that specifies how it should 
be done?

T

-- 
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/500f7758-2beb-4248-b316-912df984e57b%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 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-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.


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.


Loading fixtures inside a transaction

2016-08-03 Thread thauk
Is it possible to have the `loaddata` manage command use a transaction when 
loading a fixture?

-- 
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/965d6a76-a3db-4f3b-b8de-a0e8c30ff6a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.