Friday, October 31, 2014

Re: Actively developed/supported piston fork?

On Thursday, October 30, 2014 4:34:32 PM UTC+7, sams...@gmail.com wrote:
I've inherited an app that was written for Django 1.4, and updated it to Django 1.7.
...
Are any being actively used/fixed/supported?  Which one should I try?

While Russell Keith-Magee is definitely correct when he says "the bulk of the energy around REST tools in the Django community has moved to Django REST Framework," given that you have inherited legacy code, the good news is that there are indeed active forks of 
Piston, thanks to how widely used it was before the advent of DRF fore-runner TastyPie. The most recently active fork I know of is: https://github.com/matllubos/django-piston, which is currently actively maintained. If that doesn't work for you for any reason, let me know and I'll dig up my other, next-most-recently-active, Piston forks…

Best wishes,
Jonathan Barratt

--
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+unsubscribe@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/3ef0628f-fe4e-4186-ad74-b6906043f24e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Primary keys vs. natural keys

> On Oct 31, 2014, at 3:26 PM, Torsten Bronger <bronger@physik.rwth-aachen.de> wrote:
>
> Hallöchen!
>
> Carl Meyer writes:
>
>>> On Oct 31, 2014, at 4:19 AM, Torsten Bronger <bronger@physik.rwth-aachen.de> wrote:
>>>
>>> [...]
>>>
>>> Do you mean this:
>>>
>>> class ExternalOperator(models.Model):
>>>
>>> name = models.CharField(_("name"), max_length=30, unique=True)
>>> natural_key_field = "name"
>>>
>>> It works (at least, it doesn't abort) but I thought only fields
>>> were allowed as attributes.
>>
>> Yes, that's what I mean (though usually for clarity I would place
>> any non-field attributes in a separate visual block - separated by
>> a blank line - from field attributes). There is no requirement
>> that all class attributes of models must be fields. Django can
>> tell which are subclasses of Field and ignores the others.
>
> See https://code.djangoproject.com/ticket/5793 -- can't this be
> solved by such attributes then? I wonder because I subscribed to
> this ticket long ago for a similar reason.

True - there's nothing you could do with custom Meta attributes that can't just as well be done with class attributes. The desire for custom Meta attributes is purely a matter of API aesthetics.

Carl

--
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+unsubscribe@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/80F5A802-AC01-4137-B3C0-B8DFC67D3F4D%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

Re: Calling a function for a url tag parameter

Hey,
 
A filter would work better here if you can use one. The following should work:
 
Defined as:
@register.filter
def encode_url(link_text):
    return link_text.replace(' ', '_')
 
And in template:
{% with state_url=flow.state.description|encode_url %}
<a href="{% url 'advance-flow' flow.id state_url %}">advance</a>
{% endwith %}
 
Aubrey
 
 
On Thu, Oct 30, 2014, at 03:23 PM, Daniel Grace wrote:
Hi,
I am trying to use the url tag on some parameters, one of which needs to come from a function.
For example as follows:
{% with state_url=encode_url flow.state.description %}
<a href="{% url 'advance-flow' flow.id state_url %}">advance</a>
 
encode_url is defined as follows:
@register.simple_tag
def encode_url(link_text):
    return link_text.replace(' ', '_')
 
This causes an error on the with statement:
Request Method:GET
Request URL:http://127.0.0.1:8000/list_flows/
Django Version:1.7
Exception Type:TemplateSyntaxError
Exception Value:
'with' received an invalid token: 'flow.state.description'
 
I'm guessing that you cannot put another template tag in the "with" statement.  I cannot see a way around this.  Any ideas?
 
Thanks
 
 

Re: Auto-filling others ImageFields based on the original one

On 1/11/2014 2:35 AM, Sasa Trifunovic wrote:
> Hi,
>
> I have to save 3 versions of uploaded photo (and i dont want to use
> solr) , original one and two which are resized versions of the original one.
> I need those two additional photos as ImageFields in my model , due to
> the fact that i want to use django ORM.
>
> |
>
> |
> Class Post(model.Models):
>
> #...
> photo = models.ImageField(upload_to="photo_album")
> original_photo =
> models.ImageField(upload_to="photo_album/originals", null=True)
> thumbnail = models.ImageField(upload_to="photo_album/thumbnails",
> null=True)
> |
>
> |
>
>
> I have tried overriding the save method
>
> |
> |
> defsave(self):
> self.thumbnail.file =self.photo.file
> self.original_photo.file =self.photo.file
> super(Post,self).save()
> |
>
> |
>
> But that is not working (why?).

Try ...

def save(self, *args, **kwargs):
self.thumbnail.file = self.photo.file
self.original_photo.file = self.photo.file
super(Post,self).save(*args, **kwargs)

The args and kwargs are ORM params used to control saving. You need to
pass them back to the built-in save() method.

Good luck

>
> Any advice on how to solve this is much appreciated. 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+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/3907a3ed-3d39-4a07-8ab9-e80a9fe6b32e%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/3907a3ed-3d39-4a07-8ab9-e80a9fe6b32e%40googlegroups.com?utm_medium=email&utm_source=footer>.
> 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+unsubscribe@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/54543A69.4030403%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Re: Charfield case insensitive sorting in Model Admin

Hi Collin,

Thanks for the solution !


On Thursday, 30 October 2014 02:39:53 UTC+8, Collin Anderson wrote:
Hello,

One way to do it would be to have add an editable=False field name_sort that's a lower() version of your name field. You can update that field in the save method.

In the admin, you can tell it to order by name_sort using admin_order_field.

Collin

--
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+unsubscribe@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/e6e30209-44a1-4655-ab28-2f74017baac8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Slow SQL query

Hi Erik,
 
Maybe Users doesn't belong in the Orders table? You could move the user to a different table which stores the Order.id <-> user_id relation, which would give a fast lookup on user_id and thus easy access to the Order.id index.
Interesting idea! I'll think about it.

Thanks,
Collin
 

--
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+unsubscribe@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/ced56535-bedc-4c41-82b1-ae68b6f9066b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Primary keys vs. natural keys

Hallöchen!

Carl Meyer writes:

>> On Oct 31, 2014, at 4:19 AM, Torsten Bronger <bronger@physik.rwth-aachen.de> wrote:
>>
>> [...]
>>
>> Do you mean this:
>>
>> class ExternalOperator(models.Model):
>>
>> name = models.CharField(_("name"), max_length=30, unique=True)
>> natural_key_field = "name"
>>
>> It works (at least, it doesn't abort) but I thought only fields
>> were allowed as attributes.
>
> Yes, that's what I mean (though usually for clarity I would place
> any non-field attributes in a separate visual block - separated by
> a blank line - from field attributes). There is no requirement
> that all class attributes of models must be fields. Django can
> tell which are subclasses of Field and ignores the others.

See https://code.djangoproject.com/ticket/5793 -- can't this be
solved by such attributes then? I wonder because I subscribed to
this ticket long ago for a similar reason.

Tschö,
Torsten.

--
Torsten Bronger Jabber ID: torsten.bronger@jabber.rwth-aachen.de
or http://bronger-jmp.appspot.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+unsubscribe@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/87r3xogccd.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.

Re: Primary keys vs. natural keys

> On Oct 31, 2014, at 4:19 AM, Torsten Bronger <bronger@physik.rwth-aachen.de> wrote:
> Carl Meyer writes:
>> [...]
>>
>> There is no built in feature for this, but it doesn't seem like a
>> hard problem to solve with your own conventions. For instance,
>> rather than hardcoding the name of the natural key field inside
>> the natural_key method, make it a model class attribute,
>> e.g. MyModel.natural_key_field.
>
> Do you mean this:
>
> class ExternalOperator(models.Model):
>
> name = models.CharField(_("name"), max_length=30, unique=True)
> natural_key_field = "name"
>
> It works (at least, it doesn't abort) but I thought only fields were
> allowed as attributes.

Yes, that's what I mean (though usually for clarity I would place any non-field attributes in a separate visual block - separated by a blank line - from field attributes). There is no requirement that all class attributes of models must be fields. Django can tell which are subclasses of Field and ignores the others.

Carl

--
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+unsubscribe@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/9EE3479F-0830-46B6-82E1-6B197C48B230%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

Re: DB foreign key constraints : Django 1.7 regression ?

Ticket created at https://code.djangoproject.com/ticket/23741 , with a basic implementation (that detected missing relations on non-managed models on my project !!).

Thanks for the help !

Le jeudi 30 octobre 2014 18:28:31 UTC+1, Carl Meyer a écrit :
On 10/30/2014 06:09 AM, not...@gmail.com wrote:
> Thanks Daniel, that was it (instead of removing the migrations folder, I
> now use makemigrations).
>
> I expected everything to work without the need of migrations.
> So I guess that with django 1.7, it is simply mandatory to use migrations.
>
> It is indeed stated
> in https://docs.djangoproject.com/en/1.7/topics/migrations/#unmigrated-dependencies
>
> I guess adding a nice big system check would have helped me !
> Is that addition worthy of a ticket ?

I'm not sure off the top of my head how feasible such a check would be,
but in principle I think it would be a good idea - so yes, I'd recommend
opening a ticket.

Carl

--
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+unsubscribe@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/a858988d-d01f-40ef-b344-f2d7987402a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: pycurl and SSLv3

On Thu, Oct 30, 2014 at 2:50 PM, john <johnf@jfcomputer.com> wrote:
> Hi,
>
> On the server side of my Django website I use pycurl (version 7.20.x) to
> connect to authorize.net (to send credit card info). On Nov 4 Authorize.net
> will turn off SSLv3. So I'm wondering if my use pycurl will continue to
> work. To be honest I haven't thought about it much since the pycurl seem to
> take care of everything that Authorize.net required. Now I'm questioning if
> pycurl will continue to work and if I need to change anything - what do I
> chan.
>
> c=pycurl.Curl()
> c.setopt(c.URL, GatewayURL)
> c.setopt(c.POST, TRUE)
> c.setopt(c.SSL_VERIFYPEER, FALSE)

Why do you disable peer verification checks? Its like asking for a
MITM to come and scoop up those credit card details.

pycurl uses curl, curl can be built against OpenSSL. If your curl
library is linked against an OpenSSL library that disables all TLS and
only supports up to SSLv3, then you will have problems. That would be
quite unlikely.

Cheers

Tom

--
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+unsubscribe@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/CAFHbX1%2BboL5pBkr6ujcGG10L4ihfogT0bjRLqDjWH2VW1xJkZA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Auto-filling others ImageFields based on the original one

Hi,

I have to save 3 versions of uploaded photo (and i dont want to use solr) , original one and two which are resized versions of the original one.
I need  those two additional photos as ImageFields in my model , due to the fact that i want to use django ORM.

   
Class Post(model.Models):
    
    #...
    photo = models.ImageField(upload_to="photo_album")
    original_photo = models.ImageField(upload_to="photo_album/originals", null=True)
    thumbnail = models.ImageField(upload_to="photo_album/thumbnails", null=True)



I have tried overriding the save method 

 
    def save(self):
            
self.thumbnail.file = self.photo.file
            
self.original_photo.file = self.photo.file
            
super(Post, self).save()


But that is not working (why?).

Any advice on how to solve this is much appreciated. 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+unsubscribe@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/3907a3ed-3d39-4a07-8ab9-e80a9fe6b32e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rotate the CSRF token on every request

Hi all,

I am in the process right now of working on a web portal where we want to rotate the csrf token on each request. We intend to have a new token each time for optimal security. I was hoping someone might know more about this than I do because I've run into some difficulties that were not expected. We are using Django 1.5.7. Each request runs through the django.middleware.csrf.py  CsrfViewMIddleware middleware and a middleware we have added which should be rotating the token each time using the rotate_token function from django.middleware.csrf.py. The problem we have observed is that each time the token does rotate but then is reset in the process_view function in CsrfViewMiddleware. I modified the first few lines of CsrfViewMiddleware's process_request function slightly and found the token will now rotate as I had intended for each request.

Modified Code in django.middleware.csrf.py from CsrfViewMiddleware:

   def process_view(self, request, callback, callback_args, callback_kwargs):

        if getattr(request, 'csrf_processing_done', False):
            return None

        csrf_token = request.META['CSRF_COOKIE']     #CSRF_COOKIE is being rotating by our custom middleware
        if csrf_token == None:
            # Generate token and store it in the request, so it's
            # available to the view.
            request.META["CSRF_COOKIE"] = _get_new_csrf_key()


Django's Standard Code:

    def process_view(self, request, callback, callback_args, callback_kwargs):

        if getattr(request, 'csrf_processing_done', False):
            return None

        try:
            csrf_token = _sanitize_token(
                request.COOKIES[settings.CSRF_COOKIE_NAME])
            # Use same token next time
            request.META['CSRF_COOKIE'] = csrf_token
        except KeyError:
            csrf_token = None
            # Generate token and store it in the request, so it's
            # available to the view.
            request.META["CSRF_COOKIE"] = _get_new_csrf_key()


 I think there are a few more things that should be done here like a _sanitize_token call but this is the basic idea. The problem is I can't just modify the Django code because I don't understand the full set of possible side effects.  

Does anyone know:
1. The history of why the Django developers have set up the code in this fashion.
2. Any side effects that should be expected from making a change like the above modified Django code.
3. A way to do this without modifying the Django base code.

Also, it seems like a version of CsrfViewMiddleware that is conducive to rotating on each request would be helpful as part of Django's base code. Is a change like this worth submitting a pull request to the Django repository?

Thanks for any help in advance,
ibrw100000
 

--
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+unsubscribe@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/4c3234d2-7c2a-4a42-b2b5-fbc4b38567d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: translation of view messages and business related messages not working

Thanks Ramiro, that worked.
 I think I understand why, but there's one thing I still don't get. I have some error messages that I was marking for translation with  ugettext_noop, as I read it was a good way if I wanted for example to log the message without translation and translate it only when displaying to the user. They appeared in the .po file, translated and compile the messages but I couldn't find the way to get them to display in other language either. I first thought it was because they were flagged as fuzzy. Removed that, recompiled and still no luck. I changed to  ugettext_lazy and they are working now too, but for what understand with  ugettext_lazy it will get translated when I want to use it, so logging would get screwed.
What would the correct way to make the noop to work? I went over the documentation many times already but I just don't get what I am missing.

Thanks
Marcela

On Thursday, October 30, 2014 8:45:32 PM UTC-3, Marcela Campo wrote:
Hi,
  I am using the translation functionality in Django 1.7 successfully for plain strings in a template, so something simple like

{% trans "Edit Client" %}

works just fine.


I am now trying to translate success_message from views with the SuccessMessageMixin and also error messages that bubble up from business logic but I just can't make those work.The messages show up for translation in the .po file. For example:

# python-format
#: views/adminDashboard.py:158
#, python-format
msgid "Productive Unit %(name)s has been created."
msgstr "La Unidad Productiva %(name)s ha sido creada."

I have compiled the messages already.

In my view

....
....
from django.utils.translation import ugettext as _
class CustomerFieldUpdateView(AdminRequiredMixin, SuccessMessageMixin, UpdateView):
    model = Field
    template_name = 'ui/field_update_form.html'
    success_message = _('Productive Unit %(name)s has been updated.')
.....

In the template:
....
{% load i18n %}
....
{% if messages %}
    {% for message in messages %}
              {{ message }}
    {% endfor %}
{% endif %}
....


If I look at self.request.LANGUAGE_CODE in the view is set to 'es' but still the messages that bubble up from python code are displayed in the default ('en') whereas the plain strings in the template are correctly translated to spanish. I also tried using {% trans message.message %} or blocktrans as well, but nothing works.

Any ideas what I am missing?

Thanks!!!
Marcela





--
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+unsubscribe@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/4aa7add8-1b08-40bf-83f2-5d77202ad42e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Primary keys vs. natural keys

Hallöchen!

Carl Meyer writes:

> [...]
>
> There is no built in feature for this, but it doesn't seem like a
> hard problem to solve with your own conventions. For instance,
> rather than hardcoding the name of the natural key field inside
> the natural_key method, make it a model class attribute,
> e.g. MyModel.natural_key_field.

Do you mean this:

class ExternalOperator(models.Model):

name = models.CharField(_("name"), max_length=30, unique=True)
natural_key_field = "name"

It works (at least, it doesn't abort) but I thought only fields were
allowed as attributes.

Tschö,
Torsten.

--
Torsten Bronger Jabber ID: torsten.bronger@jabber.rwth-aachen.de
or http://bronger-jmp.appspot.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+unsubscribe@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/8738a4h78e.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.

Re: Primary keys vs. natural keys

Hi Torsten,

> On Oct 31, 2014, at 3:13 AM, Torsten Bronger <bronger@physik.rwth-aachen.de> wrote:
> Do I understand it correctly that in the Django community, it is
> preferred to use surrogate primary keys (the auto ID field) instead
> of explicitly setting primary keys?

Yes, I'd say this is true.

> Currently, I add natural_key()
> methods to many of my models, but some of them return only one
> field. Now I wonder whether I made a mistake and should have chosen
> that field as the primary key.
>
> My use case is that I need to retrieve the natural keys of all
> objects in the database of a particular model. As far as I can see,
> this can only be achieved by fetching all objects and calling the
> natural_key() method for all of them. In contrast,
>
> model.objects.values_list("pk", flat=True)
>
> is probably *much* faster.
>
> Is it possibly to specify a single field a natural key somehow
> (besides making it the PK)? For example, it is possible to add a
> Meta attribute to the model?

There is no built in feature for this, but it doesn't seem like a hard problem to solve with your own conventions. For instance, rather than hardcoding the name of the natural key field inside the natural_key method, make it a model class attribute, e.g. MyModel.natural_key_field. Then the natural_key method can return getattr(self, self.natural_key_field) (you could even implement this method just once in an abstract base or mixin), and you can also use the attribute to do your efficient query: MyModel.objects.values_list(MyModel.natural_key_field, flat=True)

There may be reasons to consider natural primary keys in your data model (though personally I think surrogates are usually a better choice), but I don't think the problem you presented implies that you made the wrong choice.

Carl

--
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+unsubscribe@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/7EC7C040-056D-422F-BE10-0707F72F230C%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

Primary keys vs. natural keys

Hallöchen!

Do I understand it correctly that in the Django community, it is
preferred to use surrogate primary keys (the auto ID field) instead
of explicitly setting primary keys? Currently, I add natural_key()
methods to many of my models, but some of them return only one
field. Now I wonder whether I made a mistake and should have chosen
that field as the primary key.

My use case is that I need to retrieve the natural keys of all
objects in the database of a particular model. As far as I can see,
this can only be achieved by fetching all objects and calling the
natural_key() method for all of them. In contrast,

model.objects.values_list("pk", flat=True)

is probably *much* faster.

Is it possibly to specify a single field a natural key somehow
(besides making it the PK)? For example, it is possible to add a
Meta attribute to the model?

Tschö,
Torsten.

--
Torsten Bronger Jabber ID: torsten.bronger@jabber.rwth-aachen.de
or http://bronger-jmp.appspot.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+unsubscribe@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/87egtoha9w.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.

Freelance Web Designer in Hyderabad,Rumenia,Turkey,Afganisthan,Turkisthan

My Self Raheem Pasha, Freelance Hyderabad based Freelance Website Designer and Developer with Five years experience in Internet, offering high-end expertise solution at freelance . Offering Web designing,Seo Services,Web Hosting,Template designing,Logo Designing,Banner Advertisement,Flash Animation,Website Marketing,Graphic Designing, Ecommerce Website development and much More services at affordable cost

For more Details:

Freelance Web Designer in Hyderabad

Contact : +91 (0) 8897931177

E-mail : rhmpasha29@gmail.com

Web:http://www.freelancerwebdesignerhyderabad.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+unsubscribe@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/bdfd1a3f-60d1-470a-9e9b-4b4a1457f3c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thursday, October 30, 2014

Re: translation of view messages and business related messages not working


On Oct 30, 2014 8:45 PM, "Marcela Campo" <marcelacampo@gmail.com> wrote:
>
> Hi,
>   I am using the translation functionality in Django 1.7 successfully for plain strings in a template, so something simple like
>
> {% trans "Edit Client" %}
>
> works just fine.
>
>
> I am now trying to translate success_message from views with the SuccessMessageMixin and also error messages that bubble up from business logic but I just can't make those work.The messages show up for translation in the .po file. For example:
>
> # python-format
> #: views/adminDashboard.py:158
> #, python-format
> msgid "Productive Unit %(name)s has been created."
> msgstr "La Unidad Productiva %(name)s ha sido creada."
>
> I have compiled the messages already.
>
> In my view
>
> ....
> ....
> from django.utils.translation import ugettext as _

Try replacing ugettext with ugettext_lazy. Read the relevante documentation for the details.

> class CustomerFieldUpdateView(AdminRequiredMixin, SuccessMessageMixin, UpdateView):
>     model = Field
>     template_name = 'ui/field_update_form.html'
>     success_message = _('Productive Unit %(name)s has been updated.')
> .....
>
> In the template:
> ....
> {% load i18n %}
> ....
> {% if messages %}
>     {% for message in messages %}
>               {{ message }}
>     {% endfor %}
> {% endif %}
> ....
>
>
> If I look at self.request.LANGUAGE_CODE in the view is set to 'es' but still the messages that bubble up from python code are displayed in the default ('en') whereas the plain strings in the template are correctly translated to spanish. I also tried using {% trans message.message %} or blocktrans as well, but nothing works.
>
> Any ideas what I am missing?
>
> Thanks!!!
> Marcela
>
>
>
>
>
> --
> 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+unsubscribe@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/be1ce953-ccee-4016-b4d6-686655755986%40googlegroups.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+unsubscribe@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/CAO7PdF8vJ5fx57V5CqmYqgtz_7Y5V%3DPNV_tx0XzgKBDXcGiMNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

translation of view messages and business related messages not working

Hi,
  I am using the translation functionality in Django 1.7 successfully for plain strings in a template, so something simple like

{% trans "Edit Client" %}

works just fine.


I am now trying to translate success_message from views with the SuccessMessageMixin and also error messages that bubble up from business logic but I just can't make those work.The messages show up for translation in the .po file. For example:

# python-format
#: views/adminDashboard.py:158
#, python-format
msgid "Productive Unit %(name)s has been created."
msgstr "La Unidad Productiva %(name)s ha sido creada."

I have compiled the messages already.

In my view

....
....
from django.utils.translation import ugettext as _
class CustomerFieldUpdateView(AdminRequiredMixin, SuccessMessageMixin, UpdateView):
    model = Field
    template_name = 'ui/field_update_form.html'
    success_message = _('Productive Unit %(name)s has been updated.')
.....

In the template:
....
{% load i18n %}
....
{% if messages %}
    {% for message in messages %}
              {{ message }}
    {% endfor %}
{% endif %}
....


If I look at self.request.LANGUAGE_CODE in the view is set to 'es' but still the messages that bubble up from python code are displayed in the default ('en') whereas the plain strings in the template are correctly translated to spanish. I also tried using {% trans message.message %} or blocktrans as well, but nothing works.

Any ideas what I am missing?

Thanks!!!
Marcela





--
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+unsubscribe@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/be1ce953-ccee-4016-b4d6-686655755986%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Actively developed/supported piston fork?

Hi,

On Thu, Oct 30, 2014 at 5:34 PM, <samslists@gmail.com> wrote:
I've inherited an app that was written for Django 1.4, and updated it to Django 1.7.

I've noticed lots of forks of Piston on the web.

Are any being actively used/fixed/supported?  Which one should I try?

Is anyone who has a fork that they are keeping up to date on this mailing list?

Finally - if it makes more sense to replace piston with something else, what would be the easiest thing to replace it with?

Thanks!

I'm not aware of any actively maintained fork of Piston. The bulk of the energy around REST tools in the Django community has moved to Django REST Framework:


It's not a drop-in replacement for Piston, though - you'll need to do some re-engineering.

Yours,
Russ Magee %-)

--
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+unsubscribe@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/CAJxq84-p_MvcpCeJmcCSM-fP%3DVJsddd%3D-S16%3DGhu%2BZRiaqn4Hg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Get form from modelformset by the model associated in template

Hi all,
I think it is a simple question but I don't know how I can get the specific form associated to a model from a modelformset inside a template.
In other words I am extending a ListView and I pass a modelformset through the context.
So in the template:
{% for object in object_list %}
    {{ object.field }}
    {{ which form of modelformset????? }}
{% endfor %}

Thank you,
Luigi

--
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+unsubscribe@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/8c6a7fc4-420c-4ebc-ad74-ea16ddcea058%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Pip type error.

Thank you ..it helped !

On Saturday, 21 June 2014 12:19:09 UTC+5:30, Timmy Blumberg wrote:
This is a much needed solution to a problem that has been plaguing my development cycle for weeks. Many "thankyous", stranger.

On Thursday, March 27, 2014 7:06:00 AM UTC-7, Dylan F. wrote:
Thanks Brian! The out-file command with ascii encoding specified fixed this for me. 

On Wednesday, September 26, 2012 1:55:31 AM UTC-4, Brian Peiris wrote:
Thanks John, that was useful.
This happens because powershell outputs UTF-16 by default. Another way to fix it is by using the out-file command with an ascii encoding specified:

pip freeze | out-file -enc ascii requirements.txt

On Sunday, March 11, 2012 4:17:59 AM UTC-4, John W. wrote:
I know it's weird to reply to myself, but just in case that somebody has the same problem. 

It seems that the problem it is in the requirements.txt, i created it using powershell and "pip.exe freeze > requirements.txt" command,
which creates a file with a name that has nullbytes in it. 
I was able to get around this problem by downloading a requirements.txt from an example project on github and modifying it.
That did the job and everything works nice.


On Saturday, March 10, 2012 6:06:23 PM UTC+2, John W. wrote:
Hi. I want to deploy a Django project on Heroku. The logic it's straightforward : create a virtualenv, install django, some other stuff, pip freeze into requirements.txt, create a git repository and git push it to project's repository. From what i've seen it seems like the service downloads the project and install virtualenv and pip on virtual server and it uses pip to install dependencies listed in requirments.txt . While pushing to remote server it looks like everything goes nicely until pip starts to install dependencies and then a error happens. I'm new to pip so maybe someone already seen this error. Thank you in advance.

Console snapshot:

ψ pip.exe freeze
Django==1.3.1
distribute
==0.6.24
versiontools
==1.8.3
(venv)

ψ more .\requirements.txt
Django==1.3.1
distribute
==0.6.24
versiontools
==1.8.3

(venv)

ψ git push heroku master
Enter passphrase for key '/c/Program Files (x86)/Vim/.ssh/id_rsa':
Counting objects: 12, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (12/12), 3.30 KiB, done.
Total 12 (delta 2), reused 0 (delta 0)

-----> Heroku receiving push
-----> Python/Django app detected
-----> Preparing virtualenv version 1.7
       
New python executable in ./bin/python
       
Installing distribute.............................................................................................................................................................................................done.
       
Installing pip...............done.
-----> Activating virtualenv
-----> Installing dependencies using pip version 1.0.2
       
Exception:
       
Traceback (most recent call last):
         
File "/tmp/build_k6zl66ydgqxp/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/basecommand.py", line 126, in main
           
self.run(options, args)
         
File "/tmp/build_k6zl66ydgqxp/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/commands/install.py", line 200, in run
           
for req in parse_requirements(filename, finder=finder, options=options):
         
File "/tmp/build_k6zl66ydgqxp/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/req.py", line 1255, in parse_requirements
           req
= InstallRequirement.from_line(line, comes_from)
         
File "/tmp/build_k6zl66ydgqxp/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/req.py", line 82, in from_line
           
elif os.path.isdir(path) and (os.path.sep in name or name.startswith('.')):
         
File "/tmp/build_k6zl66ydgqxp/lib/python2.7/genericpath.py", line 41, in isdir
           st
= os.stat(s)
       
TypeError: must be encoded string without NULL bytes, not str

       
Storing complete log in /app/.pip/pip.log
 !     Heroku push rejected, failed to compile Python/django app 

--
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+unsubscribe@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/ba517d60-d0e3-441c-a864-5073c2246018%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: re-apply migrations on restored database

a ha!

I see the table on the restored database. I always though that running the dump.sql would build an exact copy of the original database, but now I'm thinking it just drops and rebuilds the existing original tables. I will manually drop my dev database and then restore the dump again... and see what happens...

Thanks,
H.

2014-10-30 15:14 GMT-03:00 Markus Holtermann <info@markusholtermann.eu>:
Hey Hector,

There is a database table called "django_migrations" that is used to keep track of the applied migrations. I guess it's not documented, because touching it shouldn't ever be necessary.

It would be interesting to see how you ended up in a state that Django thinks all migrations have been applied, though.

/Markus


On October 30, 2014 7:07:02 PM CET, "Héctor Urbina" <hurbinas@gmail.com> wrote:
Hello,

I'm working on a development branch for a django (1.7) project. I have a couple of migrations, including a data migration, in this branch; and I already applied the migrations. After that, I took a dump of the production database (which didn't have those migrations, of course) and restored it to use in development. So, first thing I need to do is to re-apply all the development migrations to the database "again", but django says "no migrations to apply".

I can't find in the documentation how is that django knows what migrations have been applied so far, or if there is a way of changing that, in order to re-apply them.

Any help would be appreciated,

Hector.

--
Sent from my Android device with K-9 Mail. Please excuse my brevity.



--
Héctor Urbina S.
Ingeniero en Bioinformática
Fono: 82049138

--
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+unsubscribe@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/CADHcORiTRXK7RMWvgRXf4Fvqpekw5kryN0tKqyh977wqWdfzqQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.