Django formfield_for_foreignkey

2014-10-29 Thread Cristian Vargas
As i stated in this question 
 i 
am trying to follow something like this example 

.

Basically i am trying to set the queryset for a foreign key in my django 
admin.

It works as intended, but when i check the queries generated (with the help 
with django-debug-toolbar 
) i can 
notice there are too many.
I check the times that method is being called (with a print) and it is 
being accessed 3 times, with the exact same args (checked that too). Is 
that intended???...may be one of my tools???...can i fix it somehow???

Thanks for the help

-- 
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/fe46ce39-bd7b-41e7-9d25-d75b340e73c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Rendering TabuarInline inside ModelAdmin without a foreign key

2014-10-29 Thread Mario Gudelj
Here's the models code, DR:

class CRMUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(
verbose_name='Email Address',
max_length=255,
unique=True,
)
first_name = models.CharField("First Name", max_length=50, blank=True)
last_name = models.CharField("Last Name", max_length=50, blank=True)
phone = models.CharField("Billing Country", max_length=30, null=True,
blank=True)
...

class Order(models.Model):
order_code = models.CharField("Order ID", null=True, max_length=10)
status = models.IntegerField("Order Status",
choices=ORDER_STATUS_CHOICES, null=True, default=1)
user_id = models.IntegerField("User ID", null=True, blank=True)
...

Thanks for all your help on SO and this list by the way. I seem to come
across your answers a lot and they're really useful. You're a champ!

On 30 October 2014 07:06, Mario Gudelj  wrote:

> I did not produce the original model so I wouldn't know. My thinking is
> that the order model had to be independent of the user model so that the
> deletion of the user doesn't cascade down to orders. It's a mezzanine site
> and that's how it handles fk from orders to users.
> On 29/10/2014 9:27 pm, "Daniel Roseman"  wrote:
>
>> On Wednesday, 29 October 2014 03:57:36 UTC, somecallitblues wrote:
>>>
>>> Hi list,
>>>
>>> I have a table of orders where one of the columns is a IntegerField
>>> containing the id of a user who created the order.
>>>
>>> Since it's not a FK field django admin can't display these orders inline
>>> inside the user details page.
>>>
>>> I would normally use something like:
>>>
>>> class OrderInline(admin.TabularInline):
>>> extra = 0
>>> model = Order
>>>
>>> And then add that to the user model like this:
>>>
>>> inlines = [OrderInline]
>>>
>>> But it won't work without the FK.
>>>
>>> I've Googled around and tried everything I found on SO but I can't
>>> figure out how to add orders inline to my user model.
>>>
>>> I'm looking at https://docs.djangoproject.com/en/dev/_modules/django/
>>> contrib/contenttypes/admin/#GenericTabularInline and I'm thinking do I
>>> need to write a similar class or is there something easy and simple I'm
>>> missing.
>>>
>>> Cheers,
>>>
>>> Mario
>>>
>>>
>>>
>> You don't show your models, but why is it not a ForeignKey? After all, a
>> FK field is exactly what you describe, an integer field that contains the
>> ID of the model it is pointing to. So why not declare it as one?
>> --
>> DR.
>>
>> --
>> 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/fc21c60e-5a33-4e10-9f48-42c2c8c43c7e%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+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/CAHqTbjmRmLJ1OYP6ptLaJ6U9Wvq3oT1YWiu-URMAE19ahcfsGg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Slow SQL query

2014-10-29 Thread Erik Cederstrand
> Den 29/10/2014 kl. 18.15 skrev Collin Anderson :
> 
> Right, in practice it should be less than 1000 returned rows.
> 
> I've changed the code to run the query without the status != 4 clause, and 
> manually filtering that out using python, because, yes, 97% of the rows are 
> status != 4. Or maybe a subquery would be better here to say: first get me 
> all the orders for these people, _then_ filter out status=4.
> 
> As far as user_id goes, 98% of the rows have user_id=None. Shouldn't the 
> index be helpful there?

I'm not entirely sure how clever MySQL is with statistics on the indexes, so I 
can't be sure. But if user_id is almost always None, then this raises the 
question if your data model is appropriate. Your previous query examined 
300.000 rows but returned only 1 row, which tells me either your query or data 
model is holding back information on the nature of your data.

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.

Erik

-- 
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/BADB2ABD-CD46-4965-8E2F-F6715FA27CCC%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: DB foreign key constraints : Django 1.7 regression ?

2014-10-29 Thread Carl Meyer
Hi NotSqrt,

On 10/29/2014 11:53 AM, nots...@gmail.com wrote:
> Just tested the following:
> 
>   * create clean DB
>   * run syncdb
>   * compare obtained tables when using Django 1.6.8 and Django 1.7.1
> 
> My findings :
> 
> In Django 1.7, some fields with models.ForeignKey no longer get the DB
> constraint.
> 
> In Django 1.6, I indeed get (in postgresql) for instance:
> CONSTRAINT TABLE_FIELD_id_fkey FOREIGN KEY (FIELD_id)
>   REFERENCES django_content_type (id) MATCH SIMPLE
>   ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY
> DEFERRED,
> 
> The models for which it fails are always:
> 
>   * ContentType
>   * Auth.Group
>   * Auth.permission
>   * django_site
> 
> My local apps are always defined after "django.contrib.contenttypes" and
> "django.contrib.auth" in INSTALLED_APPS.
> Putting "django.contrib.contenttypes" as my last app does not change the
> DB construction.
> 
> So does it have to do with the order in INSTALLED_APPS ?
> Is it a regression ?

I don't have time to look into this and try to reproduce at the moment,
but if the situation is as you've described it (and it's not due to
something else specific to your project), it is certainly a regression
and a bug. If you can reproduce with a fixed set of steps (starting from
a fresh "startproject" for each Django version), please do file a bug at
code.djangoproject.com with those reproduction instructions. Thanks!

Carl



signature.asc
Description: OpenPGP digital signature


Re: What is the purpose of the include function?

2014-10-29 Thread Carl Meyer
Hi Ben & Daniel,

On 10/29/2014 07:41 AM, Ben Lopatin wrote:
> Hi Daniel, in this case I would think the latter would fail - the
> `include` function loads a URL conf module and then finds the
> `urlpatterns` attribute, whereas `admin.site.urls` is a class method
> that dynamically builds a list of URL patterns based on your installed
> apps. There's nothing to import in the latter case because there's no
> such `urls` module.

 `include()` can take a list of url patterns directly, too -- it doesn't
have to take a urlconf module with a `urlpatterns` attribute. In fact,
you can use ``include()`` entirely within one module, to include one set
of url patterns within another and reduce prefix repetition:

profile_patterns = [
url(r'^$', views.profile),
url(r'^edit/$', views.edit_profile),
]

urlpatterns = [
url(r'^$', views.home),
url(r'^(?P\d+)/', include(profile_patterns)),
]

> On Tuesday, October 28, 2014 5:51:48 PM UTC-4, Daniel Grace wrote:
> 
> Hi,
> In reference to urls.py what is the purpose of the include function?
>  For example what is the difference between these two lines?
> url(r'^admin/', admin.site.urls),
> url(r'^admin/', include(admin.site.urls)),

I think in part through historical accident, both ``include()`` and
``url()`` can actually take a triple of (urlpatterns, app_name,
namespace), which is what `admin.site.urls` actually is. So in this
particular case there is in fact no difference.

But this is an odd case. In the more typical cases, you'd pass
`include()` either a string dotted path to a Python module with a
`urlpatterns` attribute which is a list of url patterns, or an actual
Python module object with a `urlpatterns` attribute which is a list of
url patterns, or simply a list of urlpatterns. And in almost every case,
you'd pass `url()` a view callable.

Carl



signature.asc
Description: OpenPGP digital signature


Re: Rendering TabuarInline inside ModelAdmin without a foreign key

2014-10-29 Thread Mario Gudelj
I did not produce the original model so I wouldn't know. My thinking is
that the order model had to be independent of the user model so that the
deletion of the user doesn't cascade down to orders. It's a mezzanine site
and that's how it handles fk from orders to users.
On 29/10/2014 9:27 pm, "Daniel Roseman"  wrote:

> On Wednesday, 29 October 2014 03:57:36 UTC, somecallitblues wrote:
>>
>> Hi list,
>>
>> I have a table of orders where one of the columns is a IntegerField
>> containing the id of a user who created the order.
>>
>> Since it's not a FK field django admin can't display these orders inline
>> inside the user details page.
>>
>> I would normally use something like:
>>
>> class OrderInline(admin.TabularInline):
>> extra = 0
>> model = Order
>>
>> And then add that to the user model like this:
>>
>> inlines = [OrderInline]
>>
>> But it won't work without the FK.
>>
>> I've Googled around and tried everything I found on SO but I can't figure
>> out how to add orders inline to my user model.
>>
>> I'm looking at https://docs.djangoproject.com/en/dev/_modules/django/
>> contrib/contenttypes/admin/#GenericTabularInline and I'm thinking do I
>> need to write a similar class or is there something easy and simple I'm
>> missing.
>>
>> Cheers,
>>
>> Mario
>>
>>
>>
> You don't show your models, but why is it not a ForeignKey? After all, a
> FK field is exactly what you describe, an integer field that contains the
> ID of the model it is pointing to. So why not declare it as one?
> --
> DR.
>
> --
> 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/fc21c60e-5a33-4e10-9f48-42c2c8c43c7e%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+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/CAHqTbjkp5ZOtatEe-1kdpq_n1EYPejqzV0TjPyd-uHjNpV4qww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Do you think Django's future is threatened by JS frameworks in both client & server?

2014-10-29 Thread Javier Guerra Giraldez
On Wed, Oct 29, 2014 at 1:11 PM, Glen Jungels  wrote:
> the javascript frameworks (Node, Angular, etc) differ in that the execution
> is done client side


Node.js is a server framework.

-- 
Javier

-- 
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/CAFkDaoRCgsCoCkwAFBzTY_ukVxpUe%2BN8iZW9yWOwEHUxeFVZmA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Charfield case insensitive sorting in Model Admin

2014-10-29 Thread Collin Anderson
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+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/d1be3e21-d8c3-45f9-9b36-8d1bcdfde7cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dictionary passed to widget attr gets mutated

2014-10-29 Thread Collin Anderson
You could do this:

class FormWithoutBug(forms.Form):
attrs = {'type':'time', 'required':'true'}
session_start = 
forms.TimeField(widget=forms.TimeInput(attrs=attrs.copy()))
session_end = 
forms.TimeField(widget=forms.TimeInput(attrs=attrs.copy()))

-- 
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/c8a71146-0835-4c39-989c-53178533501b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dictionary passed to widget attr gets mutated

2014-10-29 Thread Collin Anderson
Hello,

Interesting. Sounds like something that could be documented.

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+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/ff52eaea-4d17-4cd6-bc1c-e64768f57b53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to save in inline form total sum

2014-10-29 Thread Collin Anderson
Hello,

the only problem that is save correct total sum but a hit 2 o 3 time button 
> save in the admin, not first time
> why? i don't know :(


It's probably because ModelA is saved before the individual ModelB's.

You could calculate this _after_ the ModelB inlines(?) have been saved 
using the save_related hook.
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_related

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+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/efbbf510-64f5-480d-bad7-2734e9f3d6da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generating a list of available templates

2014-10-29 Thread Collin Anderson
Hi William,
 

> for loader in settings.TEMPLATE_LOADERS:
> loader_module = 
> importlib.import_module('.'.join(loader.split('.')[:-1]))
> print '\n'.join(source for source in 
> loader_module.Loader().get_template_sources(''))
>

You could also get the loader like this:

from django.template.loader import find_template_loader
for loader_name in settings.TEMPLATE_LOADERS:
loader = find_template_loader(loader_name)
loader.get_template_sources('')  # etc

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+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/0113f972-5a48-4a88-bc84-79c435ae46c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: pre-populate tabular inline in admin

2014-10-29 Thread Collin Anderson
Hello,

This one's tricky. It may be simplest to just _create_ the empty inline 
ModelA's so they appear. Otherwise, you'll need to look at the ModelA's 
that exist in the database and figure out which ones needed to be added to 
the initial data.

You'll likely need to add the initial data using the 
get_formsets_with_inlines hook.
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_formsets_with_inlines

And you can always peak at the source code to get a better feel for what's 
going on :)
https://github.com/django/django/blob/master/django/contrib/admin/options.py

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+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/c6863bb0-0727-4354-824e-91aad404fa68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Do you think Django's future is threatened by JS frameworks in both client & server?

2014-10-29 Thread Glen Jungels
I have to agree that debugging javascript does stink.  However, the
javascript frameworks (Node, Angular, etc) differ in that the execution is
done client side whereas for Django, any PHP framework and Microsoft
ASP/C#, the execution is backend on the web server.  Depending on the
circumstance, the technologies can be complementary.  For example, I was
doing some experimenting with Angular (simple stuff show/populate a
listbox) that got data by way of a PHP webservice that pulled data from a
remote postresql database, transformed it to JSON and provided it to
Angular.
On Oct 29, 2014 1:56 PM, "Chris Hawkes"  wrote:

> As a business owner and full time Developer using C# and Visual Studio I
> do all of my website building at home in Django.  It's an amazing framework
> that is far above anything else I've tried which includes, ASP, Node.js,
> CodeIgniter, Yii and any other Python frameworks out there.  (I'll admit
> I've never gone with Ruby because I see no reason over Python)
>
> The support is not going anywhere.  If you check job trends on indeed.com
> Django is far above most other frameworks out there regarding growth over
> the last five years.
>
> I would argue there are more impressive large sites using Django than Ruby
> on Rails or Node.js.
>
> All this being said, there is definitely a trend towards SPA's.   But
> there is no reason why I wouldn't want to use Django to serve SPA's from
> within the application.  That's what I plan on doing with the latest site
> I'm working on now.  It will be truly awesome.
>
> Let's be honest, debugging in JavaScript is a nightmare.  The tools are
> getting better but I personally don't see any reason to use Node.js unless
> I'm building a chat service or something of that sort.  Ultimately Node.js
> will eventually have to read a database or do something more than I/O which
> it won't do any better than Python or Ruby.
>
> If any framework seems to be losing it's luster I would say it's Node.
> The hype was great but after starting with it, I'm thinking why am I using
> this?
>
> ASP.NET/MVC, Django and Ruby on Rails are by far the most reliable
> frameworks out there at the enterprise level.
>
>
>  --
> 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/ba05d66c-f10c-4ae9-988b-70d92a223c69%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+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/CAA_%3DsbRSwHYgxODjNwdOAjO_YkDZ%2B%3DauU10jYaJcVRWAsz9Ocw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django query in DetailView

2014-10-29 Thread Ronaldo Bahia
*This question is also in 
http://stackoverflow.com/questions/26635406/django-query-in-detailview

I have DetailVIew wich returns a list of related objects (m2m throught). It 
works just fine!

But I need to search for objects'names and it is returning all objects 
instead of only the related ones.

How can I approach this?

Thanks.

#models.pyclass Candidate(models.Model):
user = models.OneToOneField(User, primary_key=True)
birth = models.CharField(max_length=50)
...
class Job(models.Model):
candidate = models.ManyToManyField('Candidate', through='CandidateToJob')
title = models.CharField(max_length=500)
...
class CandidateToJob(models.Model):
job = models.ForeignKey(Job, related_name='applied_to')
candidate = models.ForeignKey(Candidate, related_name='from_user')
STATUS_CHOICES = (
   ('1', 'Not approved'),
   ('2', 'Approved'),
   ('3', 'Hired')
)
status = models.CharField(max_length=2, choices=STATUS_CHOICES)

My search query

 #views.py
 def get_query(query_string, search_fields):
query = None # Query to search for every search term
terms = normalize_query(query_string)
for term in terms:
or_query = None # Query to search for a given term in each field
for field_name in search_fields:
q = Q(**{"%s__icontains" % field_name: term})
if or_query is None:
or_query = q
else:
or_query = or_query | q
if query is None:
query = or_query
else:
query = query & or_query
return query
def searchcandidate(request, *args, **kwargs):
query_string = ''
found_entries = None
if ('q' in request.GET) and request.GET['q'].strip():
query_string = request.GET['q']
entry_query = get_query(query_string, ['candidate__user__first_name',   
 'candidate__user__last_name'])

found_entries = 
CandidateToJob.objects.filter(entry_query).order_by('-candidate')

return render_to_response('dashboard/candidates_results.html',
{ 'query_string': query_string, 'found_entries': found_entries },
context_instance=RequestContext(request)
)

The view with the list of objects(candidates)

class Screening(generic.DetailView):

model = Job
template_name = 'dashboard/screening.html'

def get_context_data(self, **kwargs):
context = super(Screening, self).get_context_data(**kwargs)
context['candidate_list'] = 
self.object.applied_to.all().order_by('candidate')
return context  

My urls

#urls.py
url(r'^dashboard/job/(?P\d+)/screening/$', views.Screening.as_view(), 
name='screening'),
url(r'^dashboard/job/(?P\d+)/screening/results/$', 
'companies.views.searchcandidate', name='searchcandidate'),

And the templates

#html for Screening(DetailView) in which works good



Buscar


{% for candidate in candidate_list %}
 {{ candidate }}{% endfor %}

The one in which is returning all objects instead of only the related ones

#html{% if found_entries %}
 {% for candidate in found_entries %}
  {{ candidate }}
 {% endfor %}{% endif %}

-- 
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/aa6a47b4-4043-44e1-99e4-60a0e2630358%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Do you think Django's future is threatened by JS frameworks in both client & server?

2014-10-29 Thread Chris Hawkes
As a business owner and full time Developer using C# and Visual Studio I do 
all of my website building at home in Django.  It's an amazing framework 
that is far above anything else I've tried which includes, ASP, Node.js, 
CodeIgniter, Yii and any other Python frameworks out there.  (I'll admit 
I've never gone with Ruby because I see no reason over Python)

The support is not going anywhere.  If you check job trends on indeed.com 
Django is far above most other frameworks out there regarding growth over 
the last five years.  

I would argue there are more impressive large sites using Django than Ruby 
on Rails or Node.js.  

All this being said, there is definitely a trend towards SPA's.   But there 
is no reason why I wouldn't want to use Django to serve SPA's from within 
the application.  That's what I plan on doing with the latest site I'm 
working on now.  It will be truly awesome.  

Let's be honest, debugging in JavaScript is a nightmare.  The tools are 
getting better but I personally don't see any reason to use Node.js unless 
I'm building a chat service or something of that sort.  Ultimately Node.js 
will eventually have to read a database or do something more than I/O which 
it won't do any better than Python or Ruby.  

If any framework seems to be losing it's luster I would say it's Node.  The 
hype was great but after starting with it, I'm thinking why am I using 
this?   

ASP.NET/MVC, Django and Ruby on Rails are by far the most reliable 
frameworks out there at the enterprise level. 


-- 
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/ba05d66c-f10c-4ae9-988b-70d92a223c69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


DB foreign key constraints : Django 1.7 regression ?

2014-10-29 Thread notsqrt
Hi !

Just tested the following:

   - create clean DB
   - run syncdb
   - compare obtained tables when using Django 1.6.8 and Django 1.7.1

My findings :

In Django 1.7, some fields with models.ForeignKey no longer get the DB 
constraint.

In Django 1.6, I indeed get (in postgresql) for instance:
CONSTRAINT TABLE_FIELD_id_fkey FOREIGN KEY (FIELD_id)
  REFERENCES django_content_type (id) MATCH SIMPLE
  ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY 
DEFERRED,

The models for which it fails are always:

   - ContentType
   - Auth.Group
   - Auth.permission
   - django_site

My local apps are always defined after "django.contrib.contenttypes" and 
"django.contrib.auth" in INSTALLED_APPS.
Putting "django.contrib.contenttypes" as my last app does not change the DB 
construction.

So does it have to do with the order in INSTALLED_APPS ?
Is it a regression ?

Thanks for the input !

NotSqrt

-- 
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/db34ffa6-8ee5-4d37-80ad-4cb4fbd5ef99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error was: No module named 'django.db.backends.pymysql'

2014-10-29 Thread Collin Anderson
Hello,

In your settings.py (or somewhere early in the code), run this:

import pymysql
pymysql.install_as_MySQLdb()

Then, set your BACKEND to django.db.backends.mysql.

Or, better yet, install https://github.com/PyMySQL/mysqlclient-python as 
that is our recommended choice for using MySQL with Django.
https://docs.djangoproject.com/en/1.7/ref/databases/#mysql-db-api-drivers

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+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/995eedd9-3ff4-4800-927d-97336a8504a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django model help text into database comment field

2014-10-29 Thread Collin Anderson
Hi Phillipe,

You'll likely need to run the SQL to update the comment by hand.

You can get the data from your models like this:

for field in MyModel._meta.fields:
print field.attname, field.help_text

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+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/e683d43e-27a2-4a85-a22e-5d10b3df2d2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Slow SQL query

2014-10-29 Thread Collin Anderson
Hi Erik,
 

> Ok, you're not giving much of a chance to the query planner either. The 
> cardinality of status is 10, so status!=4 potentially means "give me 90% of 
> the rows". The cardinality of user_id is a mere 12, which potentially means 
> "give me 8% of the rows". Your query could easily return 30.000 rows, 
> according to the above (since you're OR'ing user_id and account_number). 

Right, in practice it should be less than 1000 returned rows.

I've changed the code to run the query without the status != 4 clause, and 
manually filtering that out using python, because, yes, 97% of the rows are 
status != 4. Or maybe a subquery would be better here to say: first get me 
all the orders for these people, _then_ filter out status=4.

As far as user_id goes, 98% of the rows have user_id=None. Shouldn't the 
index be helpful there?

That said, a query time of 49 seconds is absurd for just 300.000 rows even 
> for a full table scan, and you should look into why.

This is probably why :) 
Name| Engine | Version | Row_format | Rows   | Avg_row_length | 
Data_length | Max_data_length | Index_length | Data_free | Auto_increment
order_order | InnoDB |  10 | Compact| 672252 |   1765 |  
1186988032 |   0 | 85639168 | 822083584 | 716087

Thanks for all the help,
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+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/7e5c0f5a-4edc-4dca-886e-99e12b5a01d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Deploy with wsgi causes python library to fail.

2014-10-29 Thread Bohdan Anderson
I can run in the testing server fine (python manage.py runserver 
0.0.0.0:8000) but once I deploy to the server I'm not even getting the 
django error page in response to it's failure.
I looked into the apache log files and all I get is a generic error 
message "[notice] child pid 17364 exit signal Segmentation fault (11)".
I thought it might be because apache is run by a different user, so I rand 
django with the test server and it works fine for the apache user.

My question is what should my next steps be in debugging, has any one else 
encountered this before?

what I'm using is
Debian
MySQL
Apache
Django 
and the python package that is not working is librets

Any direction would be appreciated.

-- 
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/d484b332-824b-4e0d-85f6-97bd64ca3d71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


"Raw query must include the primary key" when inheriting models

2014-10-29 Thread Tobias Wolff

Hi,

I have created two models as this:

|
classCampaign(models.Model):
name =models.CharField(max_length=255)

classCampaignExt(Campaign):
status =models.IntegerField()

|

In my APIView I do this:

|
defget(self,request,campaign_id,response_format=None):
campaigns =CampaignExt.objects.raw("""\
  SELECT
c.id,
c.name,
c.status
  FROM campaign c
  WHERE c.id = %(id)s
"""%{"id":campaign_id });
|

The traceback looks like this:
|
Traceback:
File".../env/lib/python3.4/site-packages/django/core/handlers/base.py"inget_response
111.response =wrapped_callback(request,*callback_args,**callback_kwargs)
File".../env/lib/python3.4/site-packages/django/views/decorators/csrf.py"inwrapped_view
57.returnview_func(*args,**kwargs)
File".../env/lib/python3.4/site-packages/django/views/generic/base.py"inview
69.returnself.dispatch(request,*args,**kwargs)
File".../env/lib/python3.4/site-packages/rest_framework/views.py"indispatch
403.response =self.handle_exception(exc)
File".../env/lib/python3.4/site-packages/rest_framework/views.py"indispatch
400.response =handler(request,*args,**kwargs)
File".../campaigns/views.py"inget
35.returnResponse({'result':serializer.data[0]})
File".../env/lib/python3.4/site-packages/rest_framework/serializers.py"indata
570.self._data =[self.to_native(item)foritem inobj]
File".../env/lib/python3.4/site-packages/rest_framework/serializers.py"in
570.self._data =[self.to_native(item)foritem inobj]
File".../env/lib/python3.4/site-packages/django/db/models/query.py"in__iter__
1553.raiseInvalidQuery('Raw query must include the primary key')

ExceptionType:InvalidQueryat /campaigns/4858
ExceptionValue:Rawquery must include the primary key
|

As I have the primary key in the query I reckon that this should work. 
But it seems that the CampaignExt model does not know about the primary 
key as if it has not inherited this from the Campaign model.


When I just create two models with a separated list of fields like this:

|
|classCampaign(models.Model):
name =models.CharField(max_length=255)

classCampaignExt(models.Model||):
name =models.CharField(max_length=255)
||status =models.IntegerField()
|
|

It works as expected. Can you help me what I am missing? Here is my 
environment:


Django 1.7.1
Python 3.4.2
Rest_Framework 2.4.3

Thanks,
   Tobias.
--
Gruß/Regards,
Tobias Wolff

/Senior Architect Workflow Solutions/
*IPONWEB GmbH*

Conrad-Niemann-Straße 28
33442 Herzebrock-Clarholz

Mobil: +49 172 1940702
eMail: two...@iponweb.net

Geschäftsführer: Thomas Servatius
Amtsgericht: Düsseldorf, HRB 72195

--
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/5450EA6E.401%40iponweb.net.
For more options, visit https://groups.google.com/d/optout.


Re: rapidsms

2014-10-29 Thread Mark Phillips
1. Perhaps reading the RapidSMS tutorial will help
http://rapidsms.readthedocs.org/en/develop/tutorial/index.html.

2. Join the RapidSMS Google group and ask questions there.

Mark



On Wed, Oct 29, 2014 at 6:27 AM, ngangsia akumbo  wrote:

> I just got a new project to build an sms app to be used to communicate
> within a particular group of people..
>
> I intend to use rapidsms . I dont even now how much to ask them. This is
> my first contract as a python programmer.
>
> Any ideas ???
>
> --
> 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/25c942e1-096b-4d3a-9c56-fe53e418b561%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+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/CAEqej2NJugmvBTAn9vnOhD7OzRjbzRfDKmCizgJAGaQs55Q%3DuQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Database field for Image Upload

2014-10-29 Thread Bill Freeman
Note that if these images will be displayed on the site it is best done by
your front end (Apache, ngnx, etc.) since the HTML to show them treats them
as a separate request, and serving static files is your front end's forte.
The front end knows how to do this with files, but probably not with
database blobs.  Thus the design followed by Django (and many other
frameworks) is to store the image as a file, and store something that
allows easy generation of the src attribute of the image tag, such as a
relative or absolute file name.

On Wed, Oct 29, 2014 at 9:14 AM, pjotr  wrote:

> https://docs.djangoproject.com/en/1.7/ref/models/fields/#imagefield
>
> The image file will not be stored in the database, but in MEDIAROOT by
> default. So maybe this is not the answer to your question.
>
> On Wednesday, October 29, 2014 10:18:30 AM UTC+1, Shubham Gupta wrote:
>>
>> Is there  any way from which i can add image  as a field so that images
>> are added into my database?
>> what data type i must use for this problem..?
>> thank you in advance
>>
>>  --
> 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/b8612d81-a510-43d7-bc7f-57d81b76d686%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+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/CAB%2BAj0tN5rvZNdm76xEdYEt4g0LipSGFTunPz7mXew8-%3D86xMg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: What is the purpose of the include function?

2014-10-29 Thread Ben Lopatin
Hi Daniel, in this case I would think the latter would fail - the `include` 
function loads a URL conf module and then finds the `urlpatterns` 
attribute, whereas `admin.site.urls` is a class method that dynamically 
builds a list of URL patterns based on your installed apps. There's nothing 
to import in the latter case because there's no such `urls` module.

On Tuesday, October 28, 2014 5:51:48 PM UTC-4, Daniel Grace wrote:
>
> Hi,
> In reference to urls.py what is the purpose of the include function?  For 
> example what is the difference between these two lines?
> url(r'^admin/', admin.site.urls),
> url(r'^admin/', include(admin.site.urls)),
>
>
>

-- 
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/9ea33c73-6a9e-4a34-a904-e062bfe88fbb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


rapidsms

2014-10-29 Thread ngangsia akumbo
I just got a new project to build an sms app to be used to communicate 
within a particular group of people..

I intend to use rapidsms . I dont even now how much to ask them. This is my 
first contract as a python programmer.

Any ideas ???

-- 
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/25c942e1-096b-4d3a-9c56-fe53e418b561%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Database field for Image Upload

2014-10-29 Thread pjotr
https://docs.djangoproject.com/en/1.7/ref/models/fields/#imagefield

The image file will not be stored in the database, but in MEDIAROOT by 
default. So maybe this is not the answer to your question.

On Wednesday, October 29, 2014 10:18:30 AM UTC+1, Shubham Gupta wrote:
>
> Is there  any way from which i can add image  as a field so that images 
> are added into my database?
> what data type i must use for this problem..?
> thank you in advance
>
>

-- 
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/b8612d81-a510-43d7-bc7f-57d81b76d686%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Smart locale fallback

2014-10-29 Thread Malte Beckmann
We got a standard locale fallback to "en" if the browser language is not 
supported by our site. 
However, it would make sense to fallback from en_AU to en_UK rather than to 
en which is essentially en_US. Or zh_hans to zh_CN which are essentially 
the same.

I am sure this can be done but I doubt I am the first person to think this 
should happen this way. Has anyone tried this before? Cheers/malte

-- 
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/aed761e0-40dd-478d-8a31-ca9013eaac11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Database field for Image Upload

2014-10-29 Thread Shubham Gupta
Is there  any way from which i can add image  as a field so that images are 
added into my database?
what data type i must use for this problem..?
thank you in advance

-- 
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/7ae05b33-f23a-4eb1-bf19-dfd604d4f4a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Charfield case insensitive sorting in Model Admin

2014-10-29 Thread Azam Alias
Hi,

I am using Django 1.7 on Python 3.4 and quite new to both Django and Python.

I would like to sort a name field (Charfield) in ModelAdmin view in 
case-insensitive way. The default sorting is case-sensitive. 

How could I sort it in case-insensitive?

Thanks in advance.

-- 
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/2d36c9ad-ab6a-4d23-9d6b-41ce64d35252%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Rendering TabuarInline inside ModelAdmin without a foreign key

2014-10-29 Thread Daniel Roseman
On Wednesday, 29 October 2014 03:57:36 UTC, somecallitblues wrote:
>
> Hi list,
>
> I have a table of orders where one of the columns is a IntegerField 
> containing the id of a user who created the order. 
>
> Since it's not a FK field django admin can't display these orders inline 
> inside the user details page.
>
> I would normally use something like:
>
> class OrderInline(admin.TabularInline):
> extra = 0
> model = Order
>
> And then add that to the user model like this:
>
> inlines = [OrderInline]
>
> But it won't work without the FK.
>
> I've Googled around and tried everything I found on SO but I can't figure 
> out how to add orders inline to my user model.
>
> I'm looking at 
> https://docs.djangoproject.com/en/dev/_modules/django/contrib/contenttypes/admin/#GenericTabularInline
>  
> and I'm thinking do I need to write a similar class or is there something 
> easy and simple I'm missing.
>
> Cheers,
>
> Mario
>
>
>
You don't show your models, but why is it not a ForeignKey? After all, a FK 
field is exactly what you describe, an integer field that contains the ID 
of the model it is pointing to. So why not declare it as one?
--
DR. 

-- 
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/fc21c60e-5a33-4e10-9f48-42c2c8c43c7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.