Re: formset - how to set a from error from formset.clean?

2015-01-29 Thread Richard Brockie
Following up - this did the trick. Thanks for the pointer.
R.

On Mon, Jan 19, 2015 at 10:40 AM, Richard Brockie 
wrote:

> Thank you - that looks like what I am looking for! I don't know how I
> missed that.
>
> I'm on 1.6 right now - another reason to move to 1.7 :)
>
> R.
>
> On Mon, Jan 19, 2015 at 9:16 AM, Collin Anderson 
> wrote:
>
>> Hi,
>>
>> You might be able to do something like:
>>
>> self.forms[3].add_error('field_name', 'error message')
>>
>>
>> https://docs.djangoproject.com/en/dev/ref/forms/api/#django.forms.Form.add_error
>>
>> Collin
>>
>> On Saturday, January 17, 2015 at 10:46:27 PM UTC-5, Richard Brockie wrote:
>>>
>>> Hi everyone,
>>>
>>> In a formset I can use the .clean() method to validate data across the
>>> formset. The formset.clean() method is run after all the form.clean()
>>> methods - this makes sense. Raising a formset ValidationError alerts the
>>> user to the problem with formset.non_form_errors.
>>>
>>> I would like to also set an error condition on one of more of the
>>> individual forms as a result of this formset validation failure to help
>>> identify the location of the problems (my formsets can be quite long and
>>> this will help guide the eye). I've spent quite a lot of time looking for
>>> such an example with no success. Is there a way I can do this?
>>>
>>> Here's some pseudo-code to outline what I want to do:
>>>
>>> call MyFormSet(BaseFormSet):
>>> def clean(self):
>>> super(MyFormSet, self).clean()
>>>
>>> # validation code goes here...
>>>
>>> if some_validation_error:
>>> raise ValidationError(...)# creates the formset error
>>> message
>>>
>>> create_error_in_identified_forms(somehow)#  I want
>>> to know how to do this bit
>>>
>>> Thanks & best wishes!
>>> R.
>>>
>>  --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/Ysef5zCb7Gc/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/ac19922b-a623-4083-9b86-e1ab4bf5892d%40googlegroups.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> R.
>
> Richard Brockie
>
> Real-time bicycle race results - www.ontheday.net
>



-- 
R.

Richard Brockie

Real-time bicycle race results - www.ontheday.net

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


Re: Accessing Django test client in setUpClass

2015-01-29 Thread Fred Stluka

Nicole,

If you can't access self.client of TestCase, you can always
allocate one yourself as:

c = Client()

See details in:
- http://www.dougalmatthews.com/2010/Jan/20/testing-your-first-django-app/

--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 1/22/15 4:08 AM, Nicole Harris wrote:
I just posted this on Stack Overflow and then realised I might have 
more luck here.


Basically, I'd like to know if I can access self.client inside 
setUpClass(cls) when setting up a Django test:

http://stackoverflow.com/questions/28084683/accessing-django-test-client-in-setupclass

If anybody has any insight on this, I'd really appreciate it :)

--
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/fb4e3cd7-a70a-4a7c-b61f-f6ef73d7e226%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/54CAAB89.9020002%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Namespace url lookup inside template of an app

2015-01-29 Thread Thorsten Sanders

Hello,

writing currently an app which should show different things based on 
namespace which is working already, but I do have problems with 
generating the right url inside the templates of that app.

I tried to use:
{% url 'myaddons:index' %}
but that always shows the same namespace url the last one attached.

Currently have defined inside that app:
urlpatterns = patterns('',
url(r'^$', 'myaddons.views.index', name='index'),
)

Then have 2 other apps in one I define:
urlpatterns = patterns('',
   url(r'^addons/', include('myaddons.urls', 
namespace='wow-myaddons', app_name='myaddons')),

)

in the other one:
urlpatterns = patterns('',
   url(r'^addons/', include('myaddons.urls', namespace='ws-myaddons', 
app_name='myaddons')),

)

The base one is:

url(r'^wow/', include('warcraft.urls')),
url(r'^ws/', include('wildstar.urls')),

With what I tried it always resolve to:
/ws/addons/

I want it to resolve to:
/wow/addons/ if called with /wow/
and
/ws/addons/ if called with /ws/

Greetings,
Thorsten

--
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/54CA96FC.8040305%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Re: Django web hosts in Canada

2015-01-29 Thread Avraham Serour
look for a vps and not a shared hosting, something like what you would get
with AWS

on the downside you will need to do everything yourself (installing and
configuring all the libraries, updating the server etc)

on the plus side it will be more flexible, it will support anything you
would like

On Thu, Jan 29, 2015 at 5:09 PM, jogaserbia  wrote:

> Hi All,
>
> I would like to deploy my first Django website in the next month or so.  I
> am looking at deployment options, but need some clarification.
>
> 1) when id doesn't matter where the servers are
>
> I understand that  in terms of PASS: heroku, AWS, and Google elastic
> beanstalk can all handle Django (python) and postres.
>
> If I want to host on a 'normal' hosting service, which would be available?
> greengeeks just told me that they support Python but not Django, which
> confused me because I thought Django was fully written in Python, so I am
> clearly not understanding the complexities of deploying.  Also, they only
> use MYSQL databases, I wrote my first app using Postgres/POSTGIS as the
> database.
>
> 2) when I need servers in Canada
>
> Due to privacy concerns, I may need to use servers that are exclusively in
> Canada.  I cannot seem to find any options on how to host Python/Django and
> postres on Canadian servers.  Does anyone have any pointers on that?
>
>
> Any advice would be appreciated, as this will be my first run at deploying.
>
> I have been through the heroku example, and it seems nice and easy to
> deploy and I can use Django and they use postgres.
>
> Ivan
>
> --
> 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/d489e516-94d8-46e2-a212-438faa404452%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/CAFWa6tLOviREvHPDT_G8K_q4E_g_NrpQuPuKKDHguE0ra%3D6isw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When do I have to call save() on a Model Instance?

2015-01-29 Thread Vijay Khemlani
yep, it's safe to do so

On Thu, Jan 29, 2015 at 3:40 PM, Tobias Dacoir  wrote:

> Thanks for answering all my questions.
>
> So it's perfectly save to call the save method at a later time? As long as
> I keep the object and a pointer to it in memory I can freely modify it in
> several Functions before finally calling save at some point in time?
>
> --
> 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/60e58468-7575-419a-80ff-67ba804988eb%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/CALn3ei377ys1nijH4gXijDOHPJ%2Bq_V6OYnS9BRCQdR5YPDQ5Ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When do I have to call save() on a Model Instance?

2015-01-29 Thread Tobias Dacoir
Thanks for answering all my questions.

So it's perfectly save to call the save method at a later time? As long as 
I keep the object and a pointer to it in memory I can freely modify it in 
several Functions before finally calling save at some point in time?

-- 
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/60e58468-7575-419a-80ff-67ba804988eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: When do I have to call save() on a Model Instance?

2015-01-29 Thread Vijay Khemlani
You could pass the user as an optional parameter to function2.

Whether you should save the user or not in each of the methods depends on
the logic of your application, or you can add a parameter to the method
(True to save the object, False otherwise)

On Thu, Jan 29, 2015 at 1:43 PM, Tobias Dacoir  wrote:

> I want to reduce the database queries, imagine I have a case like this:
>
> def function1():
> user = User.objects.get(id=1)
> user.name ="Myself"
> function2()
> function3(user)
> user.save()
>
> def function2():
> user = User.objects.get(id=1)
> user.lastname = "private"
>
> def function3(user):
> user.age = 18
>
> Even if this works (haven't tested it yet and I can imagine that at least
> function2() might be a problem), should I immeditately call .save() in each
> of those functions?
>
> Or is it possible to freely modify the model and save it at a later stage?
> If so, function2() would not see the new value of user.name of course,
> however function3 should be able to see it (but probably not user.lastname).
>
> Is there a best practice?
>
> --
> 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/18ac4a4d-b1c2-4b36-af6c-5f0932a9ba2e%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/CALn3ei2bmfKq2k8cq2wBHrzM9FKWOapBR7ZL7PuDmtuu1%3DTN%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


When do I have to call save() on a Model Instance?

2015-01-29 Thread Tobias Dacoir
I want to reduce the database queries, imagine I have a case like this:

def function1():
user = User.objects.get(id=1)
user.name ="Myself"
function2()
function3(user)
user.save()

def function2():
user = User.objects.get(id=1)
user.lastname = "private"

def function3(user):
user.age = 18

Even if this works (haven't tested it yet and I can imagine that at least 
function2() might be a problem), should I immeditately call .save() in each 
of those functions?

Or is it possible to freely modify the model and save it at a later stage? 
If so, function2() would not see the new value of user.name of course, 
however function3 should be able to see it (but probably not user.lastname).

Is there a best practice?

-- 
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/18ac4a4d-b1c2-4b36-af6c-5f0932a9ba2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django web hosts in Canada

2015-01-29 Thread jogaserbia
Hi All,

I would like to deploy my first Django website in the next month or so.  I 
am looking at deployment options, but need some clarification.

1) when id doesn't matter where the servers are

I understand that  in terms of PASS: heroku, AWS, and Google elastic 
beanstalk can all handle Django (python) and postres.

If I want to host on a 'normal' hosting service, which would be available? 
greengeeks just told me that they support Python but not Django, which 
confused me because I thought Django was fully written in Python, so I am 
clearly not understanding the complexities of deploying.  Also, they only 
use MYSQL databases, I wrote my first app using Postgres/POSTGIS as the 
database.

2) when I need servers in Canada

Due to privacy concerns, I may need to use servers that are exclusively in 
Canada.  I cannot seem to find any options on how to host Python/Django and 
postres on Canadian servers.  Does anyone have any pointers on that?


Any advice would be appreciated, as this will be my first run at deploying.

I have been through the heroku example, and it seems nice and easy to 
deploy and I can use Django and they use postgres.  

Ivan

-- 
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/d489e516-94d8-46e2-a212-438faa404452%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


sql query to annotation values e aggretate statements

2015-01-29 Thread Mauro Ziliani
Hi all.
My name's Mauro and I start to work with Django 1.7.3
I work on my project which tracks my accounting.

I need to translate a SQL query to annoteta values aggretate statements.

The application is named accounting

The models involved are:


class Nominativo(models.Model):
  nome = models.CharField(max_length=100)
  
class Impianto(models.Model):
  nome = models.CharField(max_length=100)

class Capitolo(models.Model):
  nome = models.CharField(max_length=100)
  

class Registrazione(models.Model):
  anno = models.PositiveIntegerField()
  impianto = models.ForeignKey('Impianto')
  nominativo = models.ForeignKey('Nominativo')
  capitolo = models.ForeignKey('Capitolo')

  dare = models.DecimalField(max_digits=10, decimal_places=2)
  avere = models.DecimalField(max_digita=10, decimal_places=2)


I need to translate te following sql statement

SELECT capitolo.nome, sum(dare) as uscite, sum(avere) as entrate 
FROM contabilita_registrazione 
INNER JOIN contabilita_capitolo as capitolo ON 
contabilita_registrazione.capitolo_id=capitolo.id 
WHERE anno=2014 
GROUP BY capitolo.nome 
ORDER BYcapitolo.nome;

How can obtain the same behavior using ORM?

Thanks in advance

MZ

-- 
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/2b6998bf-741e-46c1-8721-e1870e5fe608%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to get ForeignKey Related Objects?

2015-01-29 Thread Vijay Khemlani
Python has higher order functions, so you can do things like this

m = pair.answers   # m refers to the method itself

print m# Prints "method AudioQuestionPair.anwers of ..."

answers = m()  # Actually executes the method

On Thu, Jan 29, 2015 at 11:20 AM, Tobias Dacoir  wrote:

> Damn, you are right. pair.answers() works. I'm wondering why I didn't get
> a syntax error when calling it without the parenthesis (), because print
> still worked.
>
> On Thursday, January 29, 2015 at 2:59:56 PM UTC+1, Vijay Khemlani wrote:
>>
>> "answers" seems to be a method on the AudioQuestionPair class, so your
>> call should be:
>>
>> for answer in pair.answers():
>> print answer
>>
>> and "pair.answers.get.all()" does not make sense sinse "answers" is a
>> method.
>>
>> If you don't want to use a specific method, you can do this:
>>
>> answers = pair.answer_set.all()
>>
>>
>> On Thu, Jan 29, 2015 at 10:51 AM, Tobias Dacoir  wrote:
>>
>>> I have two Models as shown below. Now when I have a specific
>>> AudioQuestionPair and I do something like
>>>
>>> print pair.answers
>>>
>>>
>>>
>>> it works just fine. However I can not do:
>>>
>>> for answer in pair.answers
>>>
>>>
>>>
>>> Using pair.answers.get.all() does also not work. So I have to do
>>>
>>> answers = Answer.objects.filter(audioQuestionPair=pair)
>>>
>>>
>>>
>>> Isn't there a better way to design this? I can imagine that using
>>> objects.filter is more taxing on the database and uses more time than maybe
>>> another method?
>>>
>>>
>>> class AudioQuestionPair(models.Model):
>>> audioData = models.ForeignKey(AudioData)
>>> question = models.ForeignKey(Question)
>>> database = models.ForeignKey(Database)
>>> votes = models.PositiveIntegerField(default=0)
>>>
>>> class Meta:
>>> verbose_name = "AudioData-Question Pair"
>>> verbose_name_plural = "AudioData-Question Pairs"
>>>
>>> def answers(self):
>>> return Answer.objects.filter(audioQuestionPair=self.pk)
>>>
>>> def __str__(self):
>>> return "Database %s: AudioData %s - Question %s with %s Votes
>>> and Answers: %s" % (self.database, self.audioData, self.question, self.
>>> votes, self.answers())
>>>
>>> """
>>>  Answer for a specific Audio-Question Pair
>>>  cumulative
>>> """
>>> class Answer(models.Model):
>>> body = models.CharField(max_length=255)
>>> count = models.PositiveIntegerField(default=0)
>>> isGroundtruth = models.BooleanField(default=False)
>>> audioQuestionPair = models.ForeignKey(AudioQuestionPair)
>>>
>>> class Meta:
>>> verbose_name = "Answer to AudioQuestionPair"
>>> verbose_name_plural = "Answers to AudioQuestionPairs"
>>>
>>> def __str__(self):
>>> return "%s - %s times" % (self.body, self.count)
>>>
>>>
>>>
>>>  --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@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/e8991d3a-1d32-4655-918f-26e0877898de%
>>> 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/b66b75b7-4d6d-43ef-a72f-215b85e8c08c%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/CALn3ei1bPzZSah4LWw71gUmRg0fp-fxED-KhhRKMM0H3ABwcBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to get ForeignKey Related Objects?

2015-01-29 Thread Tobias Dacoir
Damn, you are right. pair.answers() works. I'm wondering why I didn't get a 
syntax error when calling it without the parenthesis (), because print 
still worked.

On Thursday, January 29, 2015 at 2:59:56 PM UTC+1, Vijay Khemlani wrote:
>
> "answers" seems to be a method on the AudioQuestionPair class, so your 
> call should be:
>
> for answer in pair.answers():
> print answer
>
> and "pair.answers.get.all()" does not make sense sinse "answers" is a 
> method.
>
> If you don't want to use a specific method, you can do this:
>
> answers = pair.answer_set.all()
>
>
> On Thu, Jan 29, 2015 at 10:51 AM, Tobias Dacoir  > wrote:
>
>> I have two Models as shown below. Now when I have a specific 
>> AudioQuestionPair and I do something like 
>>
>> print pair.answers
>>
>>
>>
>> it works just fine. However I can not do:
>>
>> for answer in pair.answers
>>
>>
>>
>> Using pair.answers.get.all() does also not work. So I have to do
>>
>> answers = Answer.objects.filter(audioQuestionPair=pair)
>>
>>
>>
>> Isn't there a better way to design this? I can imagine that using 
>> objects.filter is more taxing on the database and uses more time than maybe 
>> another method?
>>
>>
>> class AudioQuestionPair(models.Model):
>> audioData = models.ForeignKey(AudioData)
>> question = models.ForeignKey(Question)
>> database = models.ForeignKey(Database)
>> votes = models.PositiveIntegerField(default=0)
>>
>> class Meta:
>> verbose_name = "AudioData-Question Pair"
>> verbose_name_plural = "AudioData-Question Pairs"
>>
>> def answers(self):
>> return Answer.objects.filter(audioQuestionPair=self.pk)
>>
>> def __str__(self):
>> return "Database %s: AudioData %s - Question %s with %s Votes 
>> and Answers: %s" % (self.database, self.audioData, self.question, self.
>> votes, self.answers())
>>
>> """
>>  Answer for a specific Audio-Question Pair
>>  cumulative
>> """
>> class Answer(models.Model):
>> body = models.CharField(max_length=255)
>> count = models.PositiveIntegerField(default=0)
>> isGroundtruth = models.BooleanField(default=False)
>> audioQuestionPair = models.ForeignKey(AudioQuestionPair)
>>
>> class Meta:
>> verbose_name = "Answer to AudioQuestionPair"
>> verbose_name_plural = "Answers to AudioQuestionPairs"
>>
>> def __str__(self):
>> return "%s - %s times" % (self.body, self.count)
>>
>>
>>
>>  -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/e8991d3a-1d32-4655-918f-26e0877898de%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/b66b75b7-4d6d-43ef-a72f-215b85e8c08c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to get ForeignKey Related Objects?

2015-01-29 Thread Vijay Khemlani
"answers" seems to be a method on the AudioQuestionPair class, so your call
should be:

for answer in pair.answers():
print answer

and "pair.answers.get.all()" does not make sense sinse "answers" is a
method.

If you don't want to use a specific method, you can do this:

answers = pair.answer_set.all()


On Thu, Jan 29, 2015 at 10:51 AM, Tobias Dacoir  wrote:

> I have two Models as shown below. Now when I have a specific
> AudioQuestionPair and I do something like
>
> print pair.answers
>
>
>
> it works just fine. However I can not do:
>
> for answer in pair.answers
>
>
>
> Using pair.answers.get.all() does also not work. So I have to do
>
> answers = Answer.objects.filter(audioQuestionPair=pair)
>
>
>
> Isn't there a better way to design this? I can imagine that using
> objects.filter is more taxing on the database and uses more time than maybe
> another method?
>
>
> class AudioQuestionPair(models.Model):
> audioData = models.ForeignKey(AudioData)
> question = models.ForeignKey(Question)
> database = models.ForeignKey(Database)
> votes = models.PositiveIntegerField(default=0)
>
> class Meta:
> verbose_name = "AudioData-Question Pair"
> verbose_name_plural = "AudioData-Question Pairs"
>
> def answers(self):
> return Answer.objects.filter(audioQuestionPair=self.pk)
>
> def __str__(self):
> return "Database %s: AudioData %s - Question %s with %s Votes and
> Answers: %s" % (self.database, self.audioData, self.question, self.votes,
> self.answers())
>
> """
>  Answer for a specific Audio-Question Pair
>  cumulative
> """
> class Answer(models.Model):
> body = models.CharField(max_length=255)
> count = models.PositiveIntegerField(default=0)
> isGroundtruth = models.BooleanField(default=False)
> audioQuestionPair = models.ForeignKey(AudioQuestionPair)
>
> class Meta:
> verbose_name = "Answer to AudioQuestionPair"
> verbose_name_plural = "Answers to AudioQuestionPairs"
>
> def __str__(self):
> return "%s - %s times" % (self.body, self.count)
>
>
>
>  --
> 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/e8991d3a-1d32-4655-918f-26e0877898de%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/CALn3ei1XfLtGJCdubdaPnU%2B6i%3DsvRhvuDr5paemUKOqkK9vD5w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Best way to get ForeignKey Related Objects?

2015-01-29 Thread Tobias Dacoir
I have two Models as shown below. Now when I have a specific 
AudioQuestionPair and I do something like 

print pair.answers



it works just fine. However I can not do:

for answer in pair.answers



Using pair.answers.get.all() does also not work. So I have to do

answers = Answer.objects.filter(audioQuestionPair=pair)



Isn't there a better way to design this? I can imagine that using 
objects.filter is more taxing on the database and uses more time than maybe 
another method?


class AudioQuestionPair(models.Model):
audioData = models.ForeignKey(AudioData)
question = models.ForeignKey(Question)
database = models.ForeignKey(Database)
votes = models.PositiveIntegerField(default=0)

class Meta:
verbose_name = "AudioData-Question Pair"
verbose_name_plural = "AudioData-Question Pairs"

def answers(self):
return Answer.objects.filter(audioQuestionPair=self.pk)

def __str__(self):
return "Database %s: AudioData %s - Question %s with %s Votes and 
Answers: %s" % (self.database, self.audioData, self.question, self.votes, 
self.answers())

"""
 Answer for a specific Audio-Question Pair
 cumulative
"""
class Answer(models.Model):
body = models.CharField(max_length=255)
count = models.PositiveIntegerField(default=0)
isGroundtruth = models.BooleanField(default=False)
audioQuestionPair = models.ForeignKey(AudioQuestionPair)

class Meta:
verbose_name = "Answer to AudioQuestionPair"
verbose_name_plural = "Answers to AudioQuestionPairs"

def __str__(self):
return "%s - %s times" % (self.body, self.count)



-- 
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/e8991d3a-1d32-4655-918f-26e0877898de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Putting picture thumbnails within admin page

2015-01-29 Thread Collin Anderson
Hi,

Any luck?

Try looking at the Network tab of the developer console to see what the 
errors are.

Collin

On Monday, January 26, 2015 at 7:31:54 PM UTC-5, bradford li wrote:
>
>
> I am trying to put thumbnail pictures of my photos within my admin page. I 
> am currently running into the issue where the thumbnail isn't displayed, 
> when I click on thumbnail I am redirected to the homepage of my project 
> with this as the URL: 
>
> http://127.0.0.1:8000/media/tumblr_ngotb4IY8v1sfie3io1_1280.jpg
>
> Here is a gist of my code: 
>
> https://gist.github.com/liondancer/678752e8bf31cc7d2c63
>
> Stackoverflow question:
>
>
> http://stackoverflow.com/questions/28159740/configuring-admin-to-display-thumnails
>
> If anything else is needed please let me know! 
>
>
>
> 
>
>
>

-- 
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/d0302752-6a77-4d67-89da-f9bd27178ab1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


merge django.po and djangojs.po files

2015-01-29 Thread gipyth
Hi,

I want to keep the one language file for all extensions. 
But I can parse the js files only with

django-admin makemessages -d djangojs -l it

command.

django-admin makemessages -d django -l it -e js

does not work for me.

I have Python 2.7.8, Django 1.7, gettext-runtime-0.17,  gettext-tools-0.17 
windows instalations

Thanks in advance,


gipyth

-- 
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/838066f2-e67e-48b8-8fa0-77f5868ac60b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Disorientated by too many google-maps django packages

2015-01-29 Thread Victor
Many thanks to Mario Goodelj for the very clear example and his explanations.
Ciao
Vittorio


Il giorno 27/gen/2015, alle ore 00:12, Mario Gudelj ha scritto:

> Hey Victor,
> 
> Here's some basic JS I've used in a project to plot client locations, and to 
> show their name and phone when the marker is clicked:
> 
> var locations = {{ locations|safe }};
> 
> var map = new google.maps.Map(document.getElementById('map-canvas'), {
> zoom: 11,
> center: new google.maps.LatLng(-33.92, 151.25),
> mapTypeId: google.maps.MapTypeId.ROADMAP
> });
> var infowindow = new google.maps.InfoWindow();
> 
> var marker, i;
> 
> for (i = 0; i < locations.length; i++) {
> lat_log_split = locations[i][1].split(",");
> marker = new google.maps.Marker({
> position: new 
> google.maps.LatLng(parseFloat(lat_log_split[0]),parseFloat(lat_log_split[1])),
> map: map
> });
> 
> google.maps.event.addListener(marker, 'click', (function(marker, i) {
> return function() {
> var popup = ''+locations[i][0]+' 
> '+locations[i][2]+' href="tel:'+locations[i][3]+'">M:'+locations[i][3]+'';
> infowindow.setContent(popup);
> infowindow.open(map, marker);
> }
> })(marker, i));
> }
> You'll see that the following code is plotting the marker on the map using 
> lat and long, which I've obtained by geocoding the client's address on the 
> server side.
> 
> marker = new google.maps.Marker({
> position: new 
> google.maps.LatLng(parseFloat(lat_log_split[0]),parseFloat(lat_log_split[1])),
> map: map
> });
> 
> You have to link to maps api before this code with:
> 
> http://maps.google.com/maps/api/js?sensor=false"; 
> type="text/javascript">
> 
> I'm just passing an array inside {{ locations|safe }} where each array item 
> contains customer info. 
> 
> It's probably not the best way to do this and what George has written is a 
> better approach, but it works well for me. I think I've used something from 
> here to obtain lat and long https://pypi.python.org/pypi/django-easy-maps
> 
> Cheers,
> 
> M
> 
> 
> 
> 
> On 27 January 2015 at 03:54, George Silva  wrote:
> I would suggest a new approach here. Don't use a package that is out there.
> 
> Since your task is quite simple, you should create you webmapp using 
> JavaScript, and pull all the patient data from your django server using REST 
> or use a map server, like GeoServer, to create and render your layers on top 
> of your Google Map's Layers.
> 
> In the client side, two libraries dominate: OpenLayers and Leaflet.
> 
> Check them out.
> 
> If you need other functionality, you can code it yourself. These packages 
> have limited functions, so if you ever need anything else, you'll end up 
> hacking the package or letting it go all the way.
> 
> On Mon, Jan 26, 2015 at 2:41 PM, Victor  wrote:
> I'm working for a medical non-profit company for domiciliary assistance of 
> ill people managed by means of a django app in production.  One of the models 
> is for patients and contains, among many other pieces of info,  their 
> addresses scattered all over Rome. I would like to use a google-maps django 
> package able to put all the flags of patients' addresses on the map of Rome 
> in one shot. Googling around I found many of them and frankly feel somewhat 
> disorientated. As a matter of fact it looks as those packages are able to put 
> just one flag at a time on a map.
> In your experience is there any specific package able to suit my needs?
> Thanks
> Vittorio
> 
> --
> 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/12E97993-5E82-48EF-AE5C-443F51F79C32%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
> 
> 
> 
> -- 
> George R. C. Silva
> SIGMA Consultoria
> 
> http://www.consultoriasigma.com.br/
> 
> -- 
> 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/CAGyPVTt2bpAwzi5XVXH3sRZH7YWJEkLikdiZLTpnLPmL_KDA%3DA%40mail.gmail.com.
> 
> For more options, visit https://groups.google.com/d/optout.
> 
> 
> -- 
> You received this message because you are subscribed to the Google 

Re: Forms test run on development database instead of test database

2015-01-29 Thread Merouane Atig
Thank you for the explanation. So I suppose a better way to do it whould be 
to provide initialize the choices in the DomainForm __init__?


Le mardi 27 janvier 2015 21:58:56 UTC+1, Collin Anderson a écrit :
>
> Hi,
>
> I just tried out your project. Looking at the stacktrace, the test module 
> is importing forms (before the test starts). The forms module is running a 
> query on startup for choices.
>
> https://github.com/merwan/django-choicefield/blob/master/myapp/forms.py
>
> Don't do queries on startup. :)
>
> Collin
>
> On Monday, January 26, 2015 at 7:07:54 AM UTC-5, Merouane Atig wrote:
>>
>> Hi,
>>
>> I have a strange issue with a forms test and I would like to know if I'm 
>> doing something wrong or if it is a Django bug.
>>
>> I created a repo to reproduce the issue I have: 
>> https://github.com/merwan/django-choicefield
>>
>> I have a DomainForm class with a choice field populated from a table in 
>> the database. I'm trying to test it using the Django testing tools, but I 
>> get the error "django.db.utils.OperationalError: no such table: 
>> myapp_topleveldomain" (see the README in the Github repo for the full stack 
>> trace).
>>
>> If I first create my development database and migrate it, then I do not 
>> have any error. I expected that the test would run on the test database but 
>> it is not the case.
>>
>> My test environment should work properly as I also created a model test 
>> which runs correctly on the test database and do not need the development 
>> database.
>>
>> Can you tell me what would be the proper way to write this test so that 
>> it runs on the test database? Is it a bug with the Django testing tools or 
>> am I doing something wrong when populating my ChoiceField?
>>
>> I'm using Django 1.7.3 and Python 3.4.0
>>
>> Thanks for your 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/a072f9cd-9db7-4465-93c1-ca54482d08cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


upload_to for ImageField changes name of file being uploaded

2015-01-29 Thread bradford li
I posted a question on stackoverflow regarding my issue:

http://stackoverflow.com/questions/28205560/upload-to-value-changes-photo-name-attribute

Basically upload_to value will change my ImageField.name to the upload_to 
value

-- 
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/318a41da-b0ed-4c19-ac66-4f3244d689a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: sending email

2015-01-29 Thread James Schneider
Couple things.

I think the return statement for thankyou.html needs to get kicked in a
tab, otherwise the form will show successful every time the form is
submitted, even if it had errors.If there are errors, it will also skip
your email code, but still show as successful.

This line is very confusing:

to_emails = [u.email for u in User.objects.filter(id__in=[a.'id'])]

I don't even think a.'id' is valid syntax. More to the point, your variable
'a' is populated a few lines earlier using a get() queryset, which means it
can only contain one item. That would render the list comprehension
statement (bad syntax aside) completely useless, since you would only ever
have a single element. That also makes the id__in filter unnecessary as
well.

Which leads to another question, are you expecting your User objects to
contain the same ID as your newleave objects (for example, User.id ==
newleave.id). That is indicated by the User.objects query you are making,
and I believe you may be incorrect there as well.

Without having seen the model, I'm guessing you want the list of
administrative users that are tied to a particular leave, your query line
would probably look something like this:

to_emails = [*a.admins.all()]

Also, in your send_mail call, you are encapsulating to_emails inside of
another list, like this send_mail(..., [to_emails]). Something tells me you
probably don't need to do that, since to_emails is already a list, but I
could be wrong there as well.

-James






On Jan 27, 2015 8:55 PM, "sum abiut"  wrote:

> Can someone please guide me here. i am kinda lost, the other part is ok
> just the email part i am really lost, please help
>
> here is my view.py the email part is not working
>
> def coporateservices_authorized_Leave(request, id):
> if request.method == 'POST':
> a=newleave.objects.get(id=id)
> form = coporateservices_authoriseleave(request.POST, instance=a)
> if form.is_valid():
>form.save()
>to_emails = [u.email for u in
> User.objects.filter(id__in=[a.'id'])]
>send_mail("RBV Leave Application Email Testing", "Your Leave
> have been approved",
>   "RBV eLeave ", [to_emails])
> return render_to_response('thankyou.html')
> else:
> a=newleave.objects.get(id=id)
> form =  coporateservices_authoriseleave(instance=a)
> return render_to_response('coporate_services_leave_approvial.html',
> {'form': form}, context_instance=RequestContext(request))
>
> cheers,
>
>
>
>
>
> On Wed, Jan 28, 2015 at 7:18 AM, Collin Anderson 
> wrote:
>
>> Hi,
>>
>> You should be able to figure out which box is checked from
>> form.cleaned_data.
>>
>> Collin
>>
>> On Sunday, January 25, 2015 at 11:53:12 PM UTC-5, suabiut wrote:
>>>
>>> Hi Collin,
>>> Thank you very much for your help. its works perfectly.
>>> The next thing i want to do is to send an email to a specific user that
>>> i select on a table. when an authorized user select a user to approve his
>>> or her leave i want an email to be send to the user. so basically when i
>>> click on the checkbox on the Test User form the table below. i should get a
>>> form to approve the leave as below. now when i click on authorized Leave
>>> button an email should be send to the test user. please point me to right
>>> direction.
>>>  [image: Inline image 1]
>>>
>>> [image: Inline image 2]
>>>
>>> Cheers,
>>>
>>> On Fri, Jan 23, 2015 at 1:18 PM, Collin Anderson 
>>> wrote:
>>>
 Hi,

 Just query the users you want.

 to_emails = [u.email for u in User.objects.filter(username__in=['person1',
 'person2', 'person3'])]
 send_mail('Subject here', 'Here is the message.', from_email_address,
 to_emails)

 Collin

 On Wednesday, January 21, 2015 at 11:29:51 PM UTC-5, suabiut wrote:
>
> Thanks,
> I am trying to send email to the users that their email address is
> stored in the database on the auth_user table. can someone please point me
> to the right direction.
>
> Cheers,
>
>
> On Thu, Jan 22, 2015 at 3:03 PM, Collin Anderson 
> wrote:
>
>> Hi,
>>
>> Yes, this is possible. Something like:
>>
>> from django.core.mail import send_mail
>>
>> def authorized_leave(request):
>> form = MyForm()
>> if request.method == 'POST':
>> form = MyForm(request.POST)
>> if form.is_valid():
>> obj = form.save()
>> send_mail('Subject here', 'Here is the message.', '
>> fr...@example.com', ['t...@example.com'])
>> return redirect('/done/')
>> return render(request, 'template.html', {form: 'form'})
>>
>> Collin
>>
>>
>> On Monday, January 19, 2015 at 10:02:45 PM UTC-5, suabiut wrote:
>>>
>>> Hi,
>>> I am trying to send an email to several users once a form is submit.