Re: queryset: LEFT OUTER JOIN with extra conditions in django ORM

2015-06-06 Thread Michael Palumbo
Yes, I tried removing the all() but that does not change anything.

On Sat, Jun 6, 2015 at 3:57 PM, James Schneider 
wrote:

> Have you tried taking out the .all()? You don't need that if you're using
> filter(). I don't think that will help though.
>
> -James
> On Jun 6, 2015 12:42 PM, "Michael"  wrote:
>
>> Just to give more information about the solution using Case, When, etc.
>> Here is what I tried:
>>
>> qs = User.objects.all().annotate(modela__count=models.Count(Case(When(
>> modela__deleted_at__isnull=True, then=1
>>
>> which turns into the following SQL query:
>>
>> SELECT COUNT(CASE WHEN "modela"."deleted_at" IS NULL THEN 1 ELSE NULL END
>> ) AS "modela__count", "users".*
>> FROM "users" LEFT OUTER JOIN "modela" ON ( "users"."id" = "modela".
>> "user_id" )
>> GROUP BY "users"."id"
>>
>> By doing that, I get all the users but I get "1" (instead of 0) for "
>> modela__count" for all the users who don't have any ModelA at all.
>> Why?
>>
>> Thanks
>>
>>
>>
>> On Saturday, June 6, 2015 at 2:01:48 PM UTC-5, Michael wrote:
>>>
>>> Hello,
>>>
>>> When doing the following, the LEFT OUTER JOIN does not work as expected:
>>> not all the Users are in the result.
>>>
>>> qs = User.objects.all().filter(modela__deleted_at__isnull=True).annotate
>>> (modela__count=models.Count('modela', distinct=True))
>>>
>>>
>>> Here is the simplified version of the query generated by django:
>>> SELECT COUNT(DISTINCT "modela"."id") AS "modela__count", "users".*
>>> FROM "users"
>>> LEFT OUTER JOIN "modela" ON ( "users"."id" = "modela"."user_id" )
>>> WHERE "modela"."deleted_at" IS NULL
>>> GROUP BY "users"."id"
>>>
>>>
>>> The problem comes from the WHERE clause makes.
>>> Indeed, there is a LEFT JOIN but the later WHERE conditions forced it to
>>> be a plain JOIN. I need to pull the conditions up into the JOIN clause to
>>> make it work as intended.
>>> So, instead of
>>> LEFT OUTER JOIN "modela" ON ( "users"."id" = "modela"."user_id" )
>>> WHERE "modela"."deleted_at" IS NULL
>>>
>>> I need the following which works.
>>> LEFT OUTER JOIN "modela" ON ( "users"."id" = "modela"."user_id" ) AND
>>> "modela"."deleted_at" IS NULL
>>>
>>>
>>> How can I change the queryset to get this?
>>> I'd like to avoid the raw query.
>>> I tried another solution using Case, When, etc but I could not make it
>>> work properly either.
>>> The slight change for the LEFT OUTER JOIN seems to be the more
>>> straightforward solution anyway.
>>>
>>> Thanks
>>>
>>  --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/9a5c2554-71d4-4a13-a611-415ec11cd0f0%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/jH7gUwhwLt4/unsubscribe.
> To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVz5cf%3DTN8O59RF--15Oz6NEJy3vF5kAiR2OntZoNuXjg%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALa-rBynpHEd_or6XK2vpg6n6QtTgyDTg0rvagysSp%2BsEjT3dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: set the css class of a form widget based on the data

2014-11-14 Thread Michael Palumbo
Thanks Russell, that works well.


On Thu, Nov 13, 2014 at 11:30 PM, Russell Keith-Magee <
russ...@keith-magee.com> wrote:

> Hi Michael,
>
> The best bet would be to write a custom widget, and override the render()
> method. render() takes the name of the widget, the value to render, and a
> dictionary of attr values. In your subclass, you can override this method
> to inject the additional attributes based on the provided value - something
> like:
>
> class MyWidget(TextInput):
> def render(self, name, value, attrs=None):
> if value == SPECIAL VALUE:
> attrs['class'] = 'class1 class2'
> return super(MyWidget, self).render(name, value, attrs)
>
> This is an oversimplification - there's a few extra edge cases you'll need
> to account for - if attrs is none, or if 'class' already exists - but the
> idea should hopefully make sense.
>
> Yours,
> Russ Magee %-)
>
>
>
> On Wed, Nov 12, 2014 at 9:25 PM, Michael 
> wrote:
>
>> Hi,
>>
>> The ``attrs`` attribute of a widget allows to define the html attributes.
>> For example, setting it to ``widget.attrs['class'] = 'class1 class2'`` will
>> add ``class="class1 class2"`` on the rendered widget.
>>
>> However, how can I set them based on the data? I display an update form
>> and I'd like to change the CSS class based on the data that is going to be
>> displayed when the form is rendered.
>>
>> Where could I check for the data in order to change the ``attrs``
>> property of the widget before it is rendered?
>>
>> Thanks
>>
>>  --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/3569acd7-5bec-4df9-8960-4952b3fee8fb%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/YADHgsrm3Gk/unsubscribe.
> To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJxq849qJkr6GrqK-6FQ7phpgAAR%3Dk3c_0CWNsv%3DyuJy9rXWzg%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALa-rBxfz3H19_POKGc5fZRPD_c_vLxk3JhAeoDMzt7ZkytQ8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: form mixin for modelform ?

2014-11-14 Thread Michael Palumbo
Thanks for your response James.
I am not well familiar with the metaclasses, I do not really see how to do
it.

What do you think of adding the fields in the init this way?

extra_fields = {'extra1': forms.CharField(required=False), 'extra2':
forms.CharField(required=False)}

class ModelFormA(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ModelFormA, self).__init__(*args, **kwargs)
for name, field in extra_fields.iteritems():
self.fields[name] = field

Thanks


On Thu, Nov 13, 2014 at 11:38 PM, James Schneider 
wrote:

> Modify your Meta class to include the extra fields on the model form. The
> Meta classes are not inherited.
>
> You may also need to override the save() method on your model form to
> actually save the contents of those extra fields in the inherited form.
>
> -James
> On Nov 13, 2014 6:32 PM, "Michael"  wrote:
>
>> Hi,
>>
>> Why does the following not give a final model form with 3 fields?
>> The two extra fields are not available. If I move them directly into the
>> model form, it works but I wanted to declare these fields in a separate
>> form because I plan on reusing them in several forms.
>> Is there a way to do that?
>>
>> class FormA(forms.Form):
>> extra_field_1 = forms.CharField(required=False)
>> extra_field_2 = forms.CharField(required=False)
>>
>> class ModelFormA(FormA, forms.ModelForm):
>> class Meta:
>> model = ModelA
>> fields = ['email']
>>
>> Thanks
>> Mike
>>
>> --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/53753989-9f3b-4a46-b96a-5edf7d7ccd69%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/cwTbH2F7kZM/unsubscribe.
> To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2Be%2BciW0NwTDLRKZH9D5nPOCQfbqpen6ng_EH24B6bJ6d-xdUA%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALa-rBzc17qzBHBB3m6MkVR0nv3FchjpODyd_KAsQnTju9S5%3Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: is it possible to detect the end of the django app?

2014-10-23 Thread Michael Palumbo
Thank you Russell for your response. That confirms what I was thinking.
I am going to use a queue.

On Thu, Oct 23, 2014 at 6:10 PM, Russell Keith-Magee <
russ...@keith-magee.com> wrote:

> HI Michael,
>
> There's a problem here - Web apps don't have a lifecycle like this. The
> only part of the app lifecycle that can be relied upon is the
> request-response cycle - someone makes a response, which will eventually be
> returned as a response. Outside of that internal lifecycle, not much can be
> guaranteed. A process will have to start in order to service a request (and
> there are ways to hook into that), but there are no guarantees that this
> process will last for 1 request, 10 or 1. And there isn't a coordinated
> shutdown of the web process - the web server may choose to shut down a web
> worker at any time.
>
> If you're using a queue to perform some sort of external processing, then
> that queue should be stored *outside* the web app itself. This means using
> a message queue (like RabbitMQ), or a service that provides an analogous
> interface (like RQ, layered over Redis). That way, a short lived web
> request can push something onto the queue, and then exit immediately. The
> web request doesn't need to worry about the lifecycle of the queue - it
> just uses the queue as a service.
>
> In short - you need to stop thinking of the web server as a "program" with
> a startup, shutdown, and predictable lifecycle, and move to thinking about
> it as "a function floating in space that can be invoked" - because, in
> practice, that's what it is. If you've got anything long lived, it needs to
> live outside the web process.
>
> Yours,
> Russ Magee %-)
>
> On Fri, Oct 24, 2014 at 5:18 AM, Michael 
> wrote:
>
>> Hi,
>>
>> How to detect that the django app is stopping?
>>
>> I use some librairies that use a queue (queue.Queue) to store the data
>> that will be sent in batch.
>> They provide a flush method to flush at the end of the program to make
>> sure there’s nothing left in the queue.
>>
>> But where could I call the flush method in django?
>>
>> Thanks
>>
>>  --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/ddecba43-49b3-493c-ad35-83d02758f95f%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/R13mmDcxYRM/unsubscribe.
> To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJxq848W3m_OkRU9v29bN_AfX%3DoE_0qoh79zv_17sjQ2CSyUPg%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALa-rBwA-4Q6GXUW9gZ0kdZinStco%2B-A%2BH_fW3H5EjpOgAL9eg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: custom field for callable python object like class or function

2012-08-23 Thread Michael Palumbo
Maybe using a Model like Kurtis mentioned will be better (and easier) than 
making a custom field... ?


Le jeudi 23 août 2012 18:49:55 UTC+2, Michael Palumbo a écrit :
>
> I did not know the pickle module. This is interesting. Thanks.
> However, after playing with it, I am not sure it fits totally my need 
> because I'd like humans to be able to write a string like 
> "modulea.moduleb.MyClass" in the admin or so.
>
> So I kept trying making a custom field (instead of a Model) by creating a 
> custom 
> field, formfield and widget.
> The list view works well, even though it displays  'modulea.moduleb.MyClass'> instead of modulea.moduleb.MyClass... 
> The add page works as well, I can add a model with the value "
> modulea.moduleb.MyClass" in the field and then it works.
> BUT I have an issue with the detail page of a model.
> I get a TypeError because my field has a class reference (which is 
> callable) and the code below then instances it!
>
>
>- 
>
> c:\Users\Mike\Dropbox\development\tools\virtualenvs\django-1.4\lib\site-packages\django\forms\forms.py
> in as_widget
>1. 
>   
>   else:
>   
>   2. 
>   
>   attrs['id'] = self.html_initial_id
>   
>   3. 
>   
>   4. 
>   
>   if not only_initial:
>   
>   5. 
>   
>   name = self.html_name
>   
>   6. 
>   
>   else:
>   
>   7. 
>   
>   name = self.html_initial_name
>   
>   1. 
>   
>   return widget.render(name, self.value(), attrs=attrs)
>   
>   ...
>1. 
>   
>   2. 
>   
>   def as_text(self, attrs=None, **kwargs):
>   
>   3. 
>   
>   """
>   
>   4. 
>   
>   Returns a string of HTML for representing this as an  type="text">.
>   
>   5. 
>   
>   """
>   
>   6. 
>   
>   return self.as_widget(TextInput(), attrs, **kwargs)
>   
>   ▼ Local vars <http://127.0.0.1:8000/admin/xmlmapping/mapping/3/#>
>VariableValueauto_id
>
>u'id_mapper_class'
>
>widget
>
>
>
>name
>
>'mapper_class'
>
>self
>
>
>
>only_initial
>
>False
>
>attrs
>
>{'id': u'id_mapper_class'}
>
>- 
>
> c:\Users\Mike\Dropbox\development\tools\virtualenvs\django-1.4\lib\site-packages\django\forms\forms.py
> in value
>1. 
>   
>   """
>   
>   2. 
>   
>   Returns the value for this BoundField, using the initial value 
> if
>   
>   3. 
>   
>   the form is not bound or the data otherwise.
>   
>   4. 
>   
>   """
>   
>   5. 
>   
>   if not self.form.is_bound:
>   
>   6. 
>   
>   data = self.form.initial.get(self.name, self.field.initial)
>   
>   7. 
>   
>   if callable(data):
>   
>   1. 
>   
>   data = data()
>   
>   ...
>1. 
>   
>   else:
>   
>   2. 
>   
>   data = self.field.bound_data(
>   
>   3. 
>   
>   self.data, self.form.initial.get(self.name, 
> self.field.initial)
>   
>   4. 
>   
>       )
>   
>   5. 
>   
>   return self.field.prepare_value(data)
>   
>   6. 
>   
>   ▼ Local vars <http://127.0.0.1:8000/admin/xmlmapping/mapping/3/#>
>VariableValueself
>
>
>
>data
>
>
>
>
>
>- 
>
>
> I overrided the render method of the widget but the errors comes from 
> self.value() of the BoundField.
> How can I fix that? override that?
>
> Any other idea?
>
> Thanks.
>
>
>
> Le jeudi 23 août 2012 03:27:09 UTC+2, Melvyn Sopacua a écrit :
>>
>> On 23-8-2012 0:37, Michael Palumbo wrote: 
>> > ok thanks, so you'd rather do it with a Model than a custom field. 
>> > I actually started to make a custom field but I had a few issues while 
>> > displaying it in the admin so that's why I asked the question then. 
>>
>> You can pickle an obje

Re: custom field for callable python object like class or function

2012-08-23 Thread Michael Palumbo
I did not know the pickle module. This is interesting. Thanks.
However, after playing with it, I am not sure it fits totally my need 
because I'd like humans to be able to write a string like 
"modulea.moduleb.MyClass" in the admin or so.

So I kept trying making a custom field (instead of a Model) by creating a 
custom 
field, formfield and widget.
The list view works well, even though it displays  instead of modulea.moduleb.MyClass... 
The add page works as well, I can add a model with the value "
modulea.moduleb.MyClass" in the field and then it works.
BUT I have an issue with the detail page of a model.
I get a TypeError because my field has a class reference (which is 
callable) and the code below then instances it!


   - 
   
c:\Users\Mike\Dropbox\development\tools\virtualenvs\django-1.4\lib\site-packages\django\forms\forms.py
in as_widget
   1. 
  
  else:
  
  2. 
  
  attrs['id'] = self.html_initial_id
  
  3. 
  
  4. 
  
  if not only_initial:
  
  5. 
  
  name = self.html_name
  
  6. 
  
  else:
  
  7. 
  
  name = self.html_initial_name
  
  1. 
  
  return widget.render(name, self.value(), attrs=attrs)
  
  ...
   1. 
  
  2. 
  
  def as_text(self, attrs=None, **kwargs):
  
  3. 
  
  """
  
  4. 
  
  Returns a string of HTML for representing this as an .
  
  5. 
  
  """
  
  6. 
  
  return self.as_widget(TextInput(), attrs, **kwargs)
  
  ▼ Local vars <http://127.0.0.1:8000/admin/xmlmapping/mapping/3/#>
   VariableValueauto_id
   
   u'id_mapper_class'
   
   widget
   
   
   
   name
   
   'mapper_class'
   
   self
   
   
   
   only_initial
   
   False
   
   attrs
   
   {'id': u'id_mapper_class'}
   
   - 
   
c:\Users\Mike\Dropbox\development\tools\virtualenvs\django-1.4\lib\site-packages\django\forms\forms.py
in value
   1. 
  
  """
  
  2. 
  
  Returns the value for this BoundField, using the initial value if
  
  3. 
  
  the form is not bound or the data otherwise.
  
  4. 
  
  """
  
  5. 
  
  if not self.form.is_bound:
  
  6. 
  
  data = self.form.initial.get(self.name, self.field.initial)
  
  7. 
  
  if callable(data):
  
  1. 
  
  data = data()
  
  ...
   1. 
  
  else:
  
  2. 
  
  data = self.field.bound_data(
  
  3. 
  
  self.data, self.form.initial.get(self.name, 
self.field.initial)
  
  4. 
  
  )
  
  5. 
  
  return self.field.prepare_value(data)
  
  6. 
  
  ▼ Local vars <http://127.0.0.1:8000/admin/xmlmapping/mapping/3/#>
   VariableValueself
   
   
   
   data
   
   
   
   

   - 


I overrided the render method of the widget but the errors comes from 
self.value() of the BoundField.
How can I fix that? override that?

Any other idea?

Thanks.



Le jeudi 23 août 2012 03:27:09 UTC+2, Melvyn Sopacua a écrit :
>
> On 23-8-2012 0:37, Michael Palumbo wrote: 
> > ok thanks, so you'd rather do it with a Model than a custom field. 
> > I actually started to make a custom field but I had a few issues while 
> > displaying it in the admin so that's why I asked the question then. 
>
> You can pickle an object and store the result in a blob-type field or 
> encode it and put it in a TextArea field: 
> <http://docs.python.org/library/pickle.html#pickle> 
> It's basically what the session module is doing. Perhaps look there for 
> inspiration: 
> <
> https://docs.djangoproject.com/en/1.4/topics/http/sessions/#technical-details>
>  
>
>
> -- 
> Melvyn Sopacua 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Ak8G-USkBmUJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: custom field for callable python object like class or function

2012-08-22 Thread Michael Palumbo
ok thanks, so you'd rather do it with a Model than a custom field.
I actually started to make a custom field but I had a few issues while 
displaying it in the admin so that's why I asked the question then.


Le jeudi 23 août 2012 00:16:48 UTC+2, Kurtis a écrit :
>
> Whoops,
>
> foo = property(get_reference, set_reference)
>
> should be
>
> reference = property(get_reference, set_reference)
>
> Sorry, was reading another page to make sure I have the property code 
> right:
>
> http://stackoverflow.com/questions/1454727/do-properties-work-on-django-model-fields
>
> On Wed, Aug 22, 2012 at 6:15 PM, Kurtis Mullins 
> <kurtis@gmail.com
> > wrote:
>
>> It looks like you want to, basically, store a reference to a Python 
>> object in your Model. It shouldn't be too extremely difficult. I'd create a 
>> Model for this purpose though and just use extra methods to provide any 
>> functionality you need. Just as a quick prototypical example:
>>
>> class ReferenceModel(Model):
>> _reference = models.CharField(max_length=150)
>>
>> def get_reference(self):
>> """
>> Load the string from self._reference and use some sort of a 
>> process
>> to dynamically load the object.
>> e.g. 
>> http://stackoverflow.com/questions/547829/how-to-dynamically-load-a-python-class
>> """
>>
>> def set_reference(self, input):
>> self._reference = input
>>
>> foo = property(get_reference, set_reference)
>>
>> Anyways, just a guess at one of many ways to possibly accomplish this 
>> task.
>> 
>>
>> On Wed, Aug 22, 2012 at 5:58 PM, Michael Palumbo 
>> <michael@gmail.com
>> > wrote:
>>
>>> Hi,
>>>
>>> Do you know a custom field for a callable python object like a Class or 
>>> a function ?
>>>
>>> It could store it as a string in the DB: "module1.module2.class"  or   
>>> "module1.module2.function"
>>> With that string, it could load it as a real python object when you get 
>>> it from the DB.
>>>
>>> For example, you could do something like that:
>>>
>>> from module1.module2 import testme
>>> mymodel.process = testme
>>> mymodel.save() => stores the string "module1.module2.testme"
>>>
>>> # Later...
>>> ins = mymodel.objects.get(..)
>>> ins.process('OK') # ins.process can be called because it has been 
>>> resolved to the testme function
>>>
>>> Thanks.
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msg/django-users/-/sHDfKCKGBmEJ.
>>> To post to this group, send email to django...@googlegroups.com
>>> .
>>> To unsubscribe from this group, send email to 
>>> django-users...@googlegroups.com .
>>> For more options, visit this group at 
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/OK6b72Lrr9gJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



custom field for callable python object like class or function

2012-08-22 Thread Michael Palumbo
Hi,

Do you know a custom field for a callable python object like a Class or a 
function ?

It could store it as a string in the DB: "module1.module2.class"  or   
"module1.module2.function"
With that string, it could load it as a real python object when you get it 
from the DB.

For example, you could do something like that:

from module1.module2 import testme
mymodel.process = testme
mymodel.save() => stores the string "module1.module2.testme"

# Later...
ins = mymodel.objects.get(..)
ins.process('OK') # ins.process can be called because it has been resolved 
to the testme function

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/sHDfKCKGBmEJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



loading initial fixture of an app before another

2012-08-04 Thread Michael Palumbo
Hi,

I have initial fixtures (initial_data.json) for several apps.
The model A of App1 references the model B of App2.
I use natural keys to reference it. 
So when I sync the DB, Django tries to make a query on modelB.

However, it appears that the fixtures of my App1 are installed before the 
fixtures of my App2.
It then fails because it cannot get the modelB.

I would like the contrary: to install fixtures from App2 before.

I tried a natural_key.dependencies on the naturel_key method of the model A 
in my App1 but it does not work. (
https://docs.djangoproject.com/en/dev/topics/serialization/#dependencies-during-serialization
)
def natural_key(self):
return (self.url,)
natural_key.dependencies = ['app2.modelB']

Any idea?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ekI6Gy4r87MJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django in MovablePython

2012-07-16 Thread Michael Palumbo
Hi,

I have been recently concerned about getting a portable Django development 
environment as well. I wanted it to work on any computers without 
installing anything.
I could get it to work, I can now carry my environment and projects on a 
USB stick. :)
I assume it is a bit late for your case now but maybe it will help someone 
else.
I made a tutorial on my blog:
http://webdevon.com/setting-up-a-django-development-environment-from-scratch-on-windows/
 

Feel free to leave comment and/or send me your feedback to improve my 
"homemade" solution.
Also, updating the wiki might be nice for next people looking for it? What 
do you think?

Michael


Le vendredi 2 janvier 2009 17:57:55 UTC+1, Taser a écrit :
>
> I've installed Django using the instructions found on 
> http://code.djangoproject.com/wiki/MovablePythonInstall on a USB drive 
> and following the Django on-site tutorial. I'm getting the following 
> error when trying to do 'python manage.py syncdb'. 
>
> - - - - START error message 
> Traceback (most recent call last): 
>   File "main.py", line 1048, in  
>   File "manage.py", line 11, in  
>   File "H:\Programming\MovablePython-MegaPack\mega-pack\interpreters 
> \movpy-2.5\l 
> ib\django\core\management\__init__.py", line 340, in execute_manager 
>   File "H:\Programming\MovablePython-MegaPack\mega-pack\interpreters 
> \movpy-2.5\l 
> ib\django\core\management\__init__.py", line 295, in execute 
>   File "H:\Programming\MovablePython-MegaPack\mega-pack\interpreters 
> \movpy-2.5\l 
> ib\django\core\management\base.py", line 192, in run_from_argv 
>   File "H:\Programming\MovablePython-MegaPack\mega-pack\interpreters 
> \movpy-2.5\l 
> ib\django\core\management\base.py", line 210, in execute 
>   File "H:\Programming\MovablePython-MegaPack\mega-pack\interpreters 
> \movpy-2.5\l 
> ib\django\utils\translation\__init__.py", line 73, in activate 
>   File "H:\Programming\MovablePython-MegaPack\mega-pack\interpreters 
> \movpy-2.5\l 
> ib\django\utils\translation\__init__.py", line 36, in delayed_loader 
> IndexError: list index out of range 
> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit 
> (Intel)] on win 
> 32 
> Type "help", "copyright", "credits" or "license" for more information. 
> (InteractiveConsole) 
> >>> 
> - - - - END error Message 
>
> The only changes made from the default settings.py were: 
>
> DATABASE_ENGINE = 'sqlite3' 
> DATABASE_NAME = 'H:/Programming/MovablePython-MegaPack/mega-pack/ 
> interpreters/movpy-2.5/mytestsite/mytestsitedb.db' 
>
> Does anyone have any pointers as to how I can fix this? 
>
> Tony R. 
> aka Taser 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/HUewXJA0l54J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: JSONField: which app to choose ?

2012-07-11 Thread Michael Palumbo
Hi Matt,

Correct, using either null=True or blank=True on the field works.
However, I don't get it since I didn't click on "save", I just wanted to 
display the add page containing it. Why does it attempt to validate the 
field at this time and not wait for the form to be sent ? Maybe this is how 
Django works ?

Whatever, I think you can set a default value in the JSONField to avoid the 
error, what do you think ? I think it's handy.
improvement:
def __init__(self, *args, **kwargs):
kwargs['default'] = kwargs.get('default', '{}')
super(JSONField, self).__init__(*args, **kwargs)

It works for me.

Another point: it does not like "extra" comma right ?
{
  "nodes": { "title": "title"*,* }
}
But I guess this is wanted because JSON does not allow it ?


Michael

 

Le mercredi 11 juillet 2012 09:15:23 UTC+2, Matt Schinckel a écrit :
>
> Michael,
>
> I've been able to reproduce it: I'm not quite sure of the best way to deal 
> with it.
>
> One solution is to set either null=True, or blank=True on the field, or 
> set a default.
>
> The trick is, an empty string isn't valid JSON. I guess I've always been 
> using a default (usually of {} or [], depending upon context).
>
> Happy for you to suggest improvements, though.
>
> I believe it's actually related to 
> https://bitbucket.org/schinckel/django-jsonfield/issue/13/integrityerrors-when-using-empty-string
>
> Matt.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/OpX1uuzKTyEJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: JSONField: which app to choose ?

2012-07-10 Thread Michael Palumbo
Can you get it work in the admin ?
I don't understand why I get a ValidationError  "[u"'' is not a valid JSON 
string."] as soon as I try to reach the Add admin page of my Model...

import jsonfield
class Mapping(models.Model):
data_map4 = jsonfield.JSONField()
-
class MappingAdmin(admin.ModelAdmin):
fields = ['data_map4']
list_display = ('data_map4',)

Thanks.

Le mardi 10 juillet 2012 22:08:50 UTC+2, Reinout van Rees a écrit :
>
> On 09-07-12 20:52, Michael Palumbo wrote: 
> > Hi, 
> > 
> > I have found several implementations of a Django JSON Field. 
> > Have you ever tried one ? Which one do you recommend ? 
>
> I'm using the 'django-jsonfield' on pypi: 
> http://pypi.python.org/pypi/django-jsonfield/  
>
> It is https://bitbucket.org/schinckel/django-jsonfield/  on bitbucket. 
> I looked at it with a colleague and it seemed to have a bit more 
> validation than some others. Little things. 
>
>
> Reinout 
>
> -- 
> Reinout van Reeshttp://reinout.vanrees.org/  
> rein...@vanrees.org http://www.nelen-schuurmans.nl/  
> "If you're not sure what to do, make something. -- Paul Graham" 
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/sgpU7kPSQRUJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



JSONField: which app to choose ?

2012-07-09 Thread Michael Palumbo
Hi,

I have found several implementations of a Django JSON Field.
Have you ever tried one ? Which one do you recommend ?

Thanks.

https://github.com/bradjasper/django-jsonfield  
https://github.com/derek-schaefer/django-json-field  
https://bitbucket.org/schinckel/django-jsonfield/overview  
https://github.com/django-extensions/django-extensions/blob/master/django_extensions/db/fields/json.py
   
http://djangosnippets.org/snippets/1478/  
http://djangosnippets.org/snippets/377/  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/GBT2-LCJAz0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



how to layout a "big" project in django 1.4 - best practices ?

2012-05-15 Thread Michael Palumbo
Hi,

I have found lots of posts on how organizing a kinda big project with 
Django =<1.3 but I was wondering what could be the best option with Django 
1.4 since the default layout has changed.

I have found just this post on the internet talking about structuring a 
django 1.4 project: 
http://www.deploydjango.com/django_project_structure/index.html
What do you think?

Please feel free to share your points of views and/or explain how you 
handle it.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/7G089jM6W6gJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.